大家好,我正在编写一个 Discord 机器人,我想制作一个反应游戏,主要是,如果有人用这个 ✅ 表情符号对机器人的消息做出反应,机器人将发送一条消息。这是我的代码:
@client.command(aliases=['Game', 'GAME'])
async def game(ctx):
emoji = '✅'
message = await ctx.send("To start to game please react the message with :white_check_mark:!")
await message.add_reaction(emoji)
答案 0 :(得分:1)
您必须使用 wait_for()
函数。对于反应添加,它看起来像这样:
reaction, user = await client.wait_for('reaction_add', timeout = 30.0, check = check)
因此,您的命令将如下所示:
@client.command(aliases=['Game', 'GAME'])
async def game(ctx):
emoji = '✅'
def check(reaction, user):
return user == ctx.author && str(reaction) == emoji
message = await ctx.send("To start to game please react the message with :white_check_mark:!")
await message.add_reaction(emoji)
try:
await client.wait_for('reaction_add', timeout = 30.0, check = check)
await ctx.send('You can now start playing the game.')
except:
await message.delete() # The message will be deleted if the user doesn't react with ✅ within 30 seconds
我希望你现在知道如何完成你的游戏了。