Reputation: 414
I am writing this bit that sends a message in a specific channel in a specific guild when a new member joins:
@bot.event
async def on_member_join(member):
channel = get(member.server.channels, id=464298877823221763)
await c.send(channel,"welcome")
I am getting weird errors when a new member joins:
Ignoring exception in on_member_join
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "d:/Documents/Bots/DS BOT/self_bot.py", line 53, in on_member_join
channel = get(member.server.channels, id=464298877823221763)
AttributeError: 'Member' object has no attribute 'serve
Does anyone know how to solve this error?
Upvotes: 1
Views: 751
Reputation: 388
It's not server, but it's rather guild
, you can try this code.
@bot.event
async def on_member_join(member):
channel = bot.get_channel(channel-id)
await channel.send(f"Welcome to {member.guild.name}!")
if you want to send where ever the member joins you can just do
@bot.event
async def on_member_join(member):
await member.channel.send(f"Welcome to {member.guild.name}!")
Check out guild documentation and the member documentation or the user documentation
Note. Sometime reading the documentation is helpful, don't forget that.
If you're using it on a cog, you'll need to do this.
@commands.Cog.listener()
async def on_member_join(self, member):
channel = bot.get_channel(channel-id)
await channel.send(f"Welcome to {member.guild.name}!")
another note, i haven't touched commands.Cog.listener() in a while, so expect some errors
Upvotes: 2
Reputation: 3924
In the API you should use guild
, not server
. A member can also be in many different guilds, so using member.guild
will not work here. Try using client.get_channel(id)
.
@bot.event
async def on_member_join(member):
channel = bot.get_channel(464298877823221763)
await channel.send("welcome")
Upvotes: 1