Reputation: 41
I'm trying to make a discord bot that sends a message in a different channel, every time someone joins the server. The bot is recognizing that someone joined but it does not recognize the channel and therefore won't send a message. The channel returns as none when I try to print it, to see if it's being recognized.
intents = discord.Intents(members=True)
client=discord.Client(intents=intents)
@client.event
async def on_member_join(member):
await client.wait_until_ready()
channel = client.get_channel(id)
print(channel)
print("Recognised that a member called " + member.name + " joined")
await channel.message.send('Hello' + member.name)
Upvotes: 4
Views: 1124
Reputation: 269
It is possible that your variables names are screwing you over.
id
should be a different variable name because id
is a python keyword. Try ID
or id1
or something.
Remember also that the ID must be an integer variable for the function to recognise it.
Upvotes: 0
Reputation: 2917
You need to enable guilds intent to use get_channel
method.
intents = discord.Intents(members=True, guilds=True)
client=discord.Client(intents=intents)
Upvotes: 2