I am relatively new to discord.py, While testin my !coinflip command ive come across alot of errors, Most of them i have fixed. But one keeps coming back.
@bot.event
async def on_message(ctx):
if ctx.content.startswith('!coinflip'):
embed = discord.Embed(title='Choose heads or tails:', color=0x00ff00)
embed.set_footer(text='React with either Tails or ️ Heads to make your choice\n. If you win 10 will be added.')
msg = await ctx.channel.send(embed=embed)
await msg.add_reaction('️')
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ['', '️']
reaction, user = await bot.wait_for('reaction_add', check=check)
if str(reaction.emoji) == '️':
choice = 'heads'
else:
choice = 'tails'
flip = random.choice(['heads', 'tails'])
if choice == flip:
userid = ctx.author.id
if os.path.isfile(f"{userid}.txt"):
file = open(f"{userid}.txt")
coins = int(file.read())
newcoins = coins + 10
file = open(f"{userid}.txt", 'r')
file.close()
file = open(f"{userid}.txt", "w")
file.write(str(newcoins))
file.close()
await ctx.channel.send('You win! The coin landed on ' + flip + '.')
else:
await ctx.channel.send('You lose! The coin landed on ' + flip + '.')
This is the error shown when the code is run:
File "c:\Users\rhan\OneDrive\Bureaublad\bscly bot\discordbot.py", line 41
reaction, user = await bot.wait_for('reaction_add', check=check)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: 'await' outside async function
I have tried looking at other posts, Which surprisingly had about the same problem, But most of the answers either didnt work or were very vague.