0

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.

1
  • 1
    You need to define it as async def ... Commented Sep 28, 2020 at 9:40

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.