【问题标题】:discord.py How to send message after reacting to bot's messagediscord.py 如何在对机器人的消息做出反应后发送消息
【发布时间】:2021-04-11 07:51:12
【问题描述】:
大家好,我正在编写一个 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)
【问题讨论】:
标签:
python
discord.py
discord.py-rewrite
【解决方案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
我希望您现在了解如何完成游戏。