[英]discord.py How to send message after reacting to bot's message
Hi guys i'm coding a Discord bot and i wanted to make a reaction game and the main thing is, if someone reacts the bot's message with this ✅ emoji, bot will send a message.大家好,我正在编写一个 Discord 机器人,我想做一个反应游戏,主要的是,如果有人用这个 ✅ 表情符号对机器人的消息做出反应,机器人会发送一条消息。 Here is my code:
这是我的代码:
@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)
You have to use the wait_for()
function.您必须使用
wait_for()
function。 For reaction adding it would look like this:对于反应添加,它看起来像这样:
reaction, user = await client.wait_for('reaction_add', timeout = 30.0, check = check)
So, your command would look like this:因此,您的命令将如下所示:
@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
I hope now you get the idea on how to complete your game.我希望你现在明白如何完成你的游戏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.