0

I have this error message 'await' outside async function I am completely confused on what I am doing wrong. here is my code:

    def check(reaction, user):
      member = message.mentions[0]
      role = get(message.guild.roles, name= 'Vikings')
      fa = get(message.guild.roles, name= 'Free Agents')
      return user == member and str(reaction.emoji) == '✅' and reaction.message == message
      try:
        reaction, user = await client.wait_for('reaction_add', timeout=600, check=check)
        await member.add_roles(role)
        await member.remove_roles(fa)
        await message.channel.send(f'{member.mention} Has Accepted **Minnesota Vikings** offer in the time given')
      except asyncio.TimeoutError:
          await message.channel.send(f'{member.mention} did not come to a decision in time.')
      else:
takendarkk
  • 3,347
  • 8
  • 25
  • 37
coderman2
  • 11
  • 1
  • 2
    You just can't use the `await` keyword inside a function that is not declared a coroutine with `async def`. – Michael Szczesny Oct 19 '20 at 22:48
  • Yeah, isn't `member` a simple data structure of some kind? If so, putting `await` in front of access to that makes no sense. Not knowing the libraries involved very well, I'm guessing that the other three instances might be correct. – CryptoFool Oct 19 '20 at 23:00
  • @Steve the library looks like discord.py, and yes it's all correct usage of await. – Seth Oct 19 '20 at 23:04
  • Well, it can't ALL be right, can it? If it were, the OP wouldn't be getting that error, right? - I do admit that i had very little idea what I was talking about. That's why I didn't give a single thought to making my comment an answer :) – CryptoFool Oct 19 '20 at 23:21
  • The error is pretty clear: you can't use `await` outside an async function. In this case, `check()` is not declared `async`. A quick google search for the error finds several hits to solve the problem. – Code-Apprentice Oct 19 '20 at 23:24
  • Ok @SethPeace, I now see what you mean. His error was one of omission. Everything he shows is correct in and of itself, but not sufficient. - I'd upvote you, but I'm equally ignorant of if you're actually right or not. = I will if/once I hear that you solved the OPs problem. – CryptoFool Oct 19 '20 at 23:24
  • @Steve https://realpython.com/async-io-python/#the-asyncio-package-and-asyncawait Check this out for info – Seth Oct 20 '20 at 00:28

1 Answers1

2

Make the first line async def check(reaction, user), and call it with await.

Seth
  • 2,214
  • 1
  • 7
  • 21