到目前为止,我已经让机器人回答了命令,但现在我希望机器人在有人做出反应后回复,这是我尝试过的代码:
@client.command()
async def war(ctx):
embed = discord.Embed(title='War', description='You are starting a war, do you want to continue?', color=0x00000)
msg = await ctx.send(embed=embed)
await msg.add_reaction(emojigood)
await msg.add_reaction(emojibad)
async def on_reaction_add(reaction, user):
if reaction.emoji == emojigood:
embed = discord.Embed(title='War', description='Please now choose a country', color=0x00000)
await channel.send(embed=embed)
答案 0 :(得分:0)
这是一段示例代码,使用您的示例解释 bot.wait_for() 方法,官方文档也有示例以及有效的方法和属性 Here
@client.command()
async def war(ctx):
embed = discord.Embed(title='War', description='You are starting a war, do you want to continue?', color=0x00000)
msg = await ctx.send(embed=embed)
await msg.add_reaction(emojigood)
await msg.add_reaction(emojibad)
def check(r):
return (r.emoji == emojigood or r.emoji == emojibad) and r.message == msg
#Checks whether the message is the same, and the emoji is one of the accepted ones, and returns either True or False
r = await ctx.bot.wait_for('reaction_add', check=check)
#this is equivalent to a event listener within your command, it will stop there until a reaction that meets the requirements has been found
#(This won't block other commands and functions)
if r.emoji == emojigood:
embed1 = discord.Embed(title='War', description='Please now choose a country', color=0x00000)
await ctx.send(embed=embed1)