Issue
I am trying to write a bot for Discord but I keep getting an error message:
File "bot.py", line 33 await member.create_dm() ^ SyntaxError: 'await' outside async function
I am trying to get the bot to send a DM to a person who has just joined the server.
@client.event
@asyncio.coroutine
def on_member_join(member):
await member.create_dm()
member.dm_channel.send("Hi and welcome!")
I would very much appreciate your help.
Solution
Your code should look like this:
@client.event
@asyncio.coroutine
async def on_member_join(member):
await member.create_dm()
member.dm_channel.send("Hi and welcome!")
add async
before def
for more information about async in python consider reading this: https://docs.python.org/3/library/asyncio-task.html
Answered By - Mogi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.