I got an error in the whole code below. I would like to seek help with the error. Can I ask for help by looking at the code below?
async def ban(ctx, member: discord.Member, *, reason: typing.Optional[str] = "사유 없음."):
await ctx.message.delete()
author = ctx.message.author
embed = None
ch = bot.get_channel(id=772349649553850368)
mesge = await ctx.send("차단을 시킬까요?")
await mesge.add_reaction('✅')
await mesge.add_reaction('❌')
def check1(reaction, user):
return user == ctx.message.author and str(reaction.emoji) == "✅"
try:
reaction, user = await bot.wait_for("reaction_add", timeout = 30.0, check = check1)
embed = discord.Embed(title="종합게임 커뮤니티 제재내역 - 차단", description=f'담당자 : {author.mention} \n대상자 : {member.mention} \n제재사유 : {reason} \n\n위와 같은 사유로 인해 제재처리 되었습니다.', color=0xff0000)
embed.set_author(name=f"{str(member)}님을 서버에서 영구적으로 차단했어요.", icon_url=member.avatar_url_as(static_format='png', size=2048))
embed.set_footer(text=f'처리 시각 - {str(now.year)} 년 {str(now.month)} 월 {str(now.day)} 일 | {str(now.hour)} 시 {str(now.minute)} 분 {str(now.second)}초 - 담당자 : {author.display_name}')
await ch.send(embed=embed)
await member.send(embed=embed)
await ctx.guild.ban(member, reason=f'사유 : {reason} - 담당자 : {author.display_name}')
except asyncio.TimeoutError:
print("Timeout")
def check2(reaction, user):
return user == ctx.message.author and str(reaction.emoji) == "❌"
try:
reaction, user = await bot.wait_for("reaction_add", timeout = 30.0, check = check2)
await ctx.send("취소되었다")
except asyncio.TimeoutError:
print("Timeout")
The following error appears in the above code.
reaction, user = await bot.wait_for("reaction_add", timeout = 30.0, check = check1)
^
SyntaxError: 'await' outside async function
If you know how to fix it, please help.
I used a translator.
def check1toasync def check1anddef check2toasync def check2? I haven't done much with async/await, but that is what I would try first as it seems to be what the error message is suggesting you do.check1... you want to dedent that code so that it is inban.check2. you put the following try inside the function when it should be dedented 4 spaces to the left so that it is part of the parent function.