Reputation: 63
So I currently have my own music bot that I coded using Discord.py. However, I am trying to add the on_member_join() and on_member_remove() methods, so that I can be notified using my own custom messages when someone leaves and joins(Discord's built in feature is fine, but it doesn't work when someone leaves, hence why I'm doing this)
So I have a channel called welcome-leave on my server, which is where I want those welcome/leave messages to be printed by the bot. However, I'm not sure how to go about doing that.
@bot.event
async def on_member_join(member):
server = member.server.default_channel
fmt = 'Welcome to the {1.name} Discord server, {0.mention}, please read the
rules and enjoy your stay.'
await bot.send_message(server, fmt.format(member, member.server))
@bot.event
async def on_member_remove(member):
server = member.server.default_channel
fmt = '{0.mention} has left/been kicked from the server.'
await bot.send_message(server, fmt.format(member, member.server))
This is currently my setup, but obviously it doesn't work. The error I get is that the Destination must either be Channel, PrivateChannel, User, or Object.
I don't really have any idea on how to make my bot print these messages to that specific channel on my server. Any help would be really appreciated.
Upvotes: 3
Views: 4996
Reputation: 3205
You cannot send a message to a server anymore, that only worked because default channels shared the same ID as the server.
Now you need to find a channel to send the message to instead of just using the server
channel = member.server.get_channel("CHANNEL_ID")
await bot.send_message(channel, ...)
Upvotes: 3