Reputation: 15
I am trying to add the on_member_join() methods, so that I can be notified using my own custom messages when someone joins.
So I have a channel called main-channel on my server, which is where I want those welcome messages to be printed by the bot. However, I'm not sure how to go about doing that. This is currently my setup, but it doesn't work.
The error I get is:
Ignoring exception in on_member_join Traceback (most recent call last): File "C:\Users\frenc\PycharmProjects\Discord\discord\client.py", line 255, in _run_event await coro(*args, **kwargs) File "C:/Users/frenc/PycharmProjects/Discord/prova.py", line 18, in on_member_join await channel.send("Benvenuto nel Server!") TypeError: can't send non-None value to a just-started coroutine C:\Users\frenc\PycharmProjects\Discord\discord\client.py:262: RuntimeWarning: coroutine 'Member._get_channel' was never awaited pass
I don't really have any idea on how to make my bot print these messages to that specific channel on my server.
I use the latest version of discord and Python 3.6.
import discord
client = discord.Client()
@client.event
async def on_ready():
print('logged in as')
print(client.user.name)
print(client.user.id)
print('-----')
@client.event
async def on_member_join(member):
print("Recognised that a member called " + member.name + " joined")
channel = member._get_channel()
await channel.send("Welcome to the server!")
print("Sent message to " + member.name)
role = discord.utils.get(member.server.roles, name="@everyone")
await member.add_roles(member, role)
print("Added role '" + role.name + "' to " + member.name)
client.run(myToken)
Upvotes: 1
Views: 5494
Reputation: 60944
You're seeing this error because you did not await _get_channel
. Coroutines/generators have a send
method that has nothing to do with the send
method of Messageable
objects.
You shouldn't be using that coroutine anyway, as Member
objects are themselves messageable:
@client.event
async def on_member_join(member):
print("Recognised that a member called " + member.name + " joined")
await member.send("Welcome to the server!")
print("Sent message to " + member.name)
# Probably unnecessary
role = discord.utils.get(member.server.roles, name="@everyone")
await member.add_roles(member, role)
print("Added role '" + role.name + "' to " + member.name)
If @everyone
is supposed to be the default role, you don't need to add it to members, they will get it automatically (the point being that everyone has the everyone
role at all times).
Upvotes: 2