discord.py如何在响应bot的消息后发送消息

2024-05-16 12:51:44 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,伙计们,我正在编写一个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)

Tags: client信息game游戏消息密码message机器人
1条回答
网友
1楼 · 发布于 2024-05-16 12:51:44

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

我希望你现在能了解如何完成游戏

相关问题 更多 >