The code is below
@client.event
async def on_member_join(Member: discord.member):
# Welcome message I guess
channel = discord.utils.get(Member.guild.channels, name='☭│chat')
embed = discord.Embed(
title="A new member has joined the server :grin:",
description=f"Thanks for joining {Member.mention} \n Hope you brought pizza!!",
)
embed.set_image(url=Member.avatar_url)
try:
await channel.send(embed=embed)
finally:
await channel.send(":skull:")
The error is described in the title, the welcome message really never seems to work because the channel is apparently a "None" object, is the issue the channel declaration?
>Solution :
I am assuming you are using the discordpy module.
According to its documentation, the discord.utils.get() function will return None if "nothing is found that matches the attributes passed".
This is occouring in your code, and so the later channel.send() fails. To solve this, consider adding an except AttributeError as e clause to your (conveniently placed) try-finally statement, and within it check if the type of channel is None.
try:
await channel.send(embed=embed)
except AttributeError as e:
if channel is None: # None is a singleton (unique) object, so all none instances satisfy this 'is' expression.
... you can now know that no channel could be attained
@Barmar correctly said that the finally statement will be executed even after the exception is caught (and so an error will still occour). This can be circumvented by encapsulating the contents of the finally cause in another try-except clause pair [though this is somewhat unattractive].