discord.py 回复机器人消息后如何发送消息

discord.py How to send message after reacting to bot's message

大家好,我正在编写一个 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)

你必须使用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

我希望你现在知道如何完成你的游戏了。