首页 > 解决方案 > 如何在调用函数时使用 discord.py 添加反应?

问题描述

我一直在使用 discord.py,我想创建一个在调用命令时与一组特定表情符号做出反应的函数。假设前缀是//.

如果我想调用 //dinosauce,我希望机器人用:thumbsupand做出反应:thumbsdown。我该怎么做呢?

这是我的代码:

@client.command()
async def dinosauce(ctx, *, message):
    emojis = [':thumbsup:', ':thumbsdown:']
    await discord.Message.add_reaction(emoji=emojis)

标签: pythonasync-awaitdiscordbotsdiscord.py

解决方案


您可以通过\:thumbsup:在 discord 中使用并复制过去来获取表情符号。

@client.command()
async def dinosauce(ctx, *, message):
    await ctx.message.add_reaction('')
    await ctx.message.add_reaction('')

在另一种方法中,您可以让机器人发送消息并删除原始消息。

@client.command()
async def dinosauce(ctx, *, message):
    await ctx.message.delete()
    msg = await ctx.send(message)
    await msg.add_reaction('')
    await msg.add_reaction('')

参考:

Message.add_reaction


推荐阅读