我有一个问题,我不知道该怎么做.

基本上,我有一个机器人,如果他检测到一个词,它就会发送消息. 现在,我想添加根据添加react 的人修改该消息的可能性(机器人在发送的每条消息中添加3个react ).

到目前为止,它工作正常,我的机器人响应并添加了3个react ,但现在我不明白如何让我的机器人编辑他的消息(我甚至不能让机器人说谁点击了一个react ),同时也删除了react .

我已经阅读了文档,阅读了很多论坛,但我找不到一种方法来让它发挥作用…… 请帮帮忙=)

blue = '<:blue:1033370324135333898>'
red = '<:red:1033370379663704148>'
yellow = '<:yellow:1033370423078952970>'

@client.event
async def on_message(message):
    if 'ping' in message.content.lower():
        if message.channel.id == 1032275628470308895:
            channel = client.get_channel(1032275628470308895)
            react = await channel.send('pong!')
            await react.add_reaction(blue)
            await react.add_reaction(red)
            await react.add_reaction(yellow)
            
@client.event
async def on_raw_reaction_add(payload):

# and then I don't know what to do, everything I've tried doesn't work
# I wanted to modify the message to (for example "{user} said blue pong!" and remove the reaction the user just use, and just keep the 3 from the bot)
# And then if another user use the yellow reaction, the bot modify his message to for example "{user] said yellow pong!"
# That could be great if the message was edited but keeping what was said before (in that case "pong! \n{user} said blue pong! \n{user} said yellow pong!")
# And last thing, if possible I want the bot to remove all reactions including his after 30mins

推荐答案

https://discordpy.readthedocs.io/en/stable/api.html?highlight=on_raw_reaction_add#discord.RawReactionActionEvent

事件ON_RAW_REACTION_ADD返回一个RawReactionActionEvent类的有效负载.

从这个有效负载中,您可以获得可用于获取消息的Message_id(例如使用discord.utils),然后您可以使用类方法edit编辑该消息

https://discordpy.readthedocs.io/en/latest/api.html#discord.Message.remove_reaction

Discordmessage对象有一个名为Remove Reaction的方法,当你向它传递一个表情符号和成员对象时,它可以删除react .

https://discordpy.readthedocs.io/en/latest/api.html#discord.Reaction.remove

您还可以从Reaction对象本身使用类方法remove

这些资源应该足以让您编写问题的解决方案:)

Python相关问答推荐

追溯(最近最后一次调用):文件C:\Users\Diplom/PycharmProject\Yolo01\Roboflow-4.py,第4行,在模块导入roboflow中

将数据框架与导入的Excel文件一起使用

将两只Pandas rame乘以指数

在Python Attrs包中,如何在field_Transformer函数中添加字段?

什么相当于pytorch中的numpy累积ufunc

OR—Tools CP SAT条件约束

无法使用DBFS File API路径附加到CSV In Datricks(OSError Errno 95操作不支持)

如何在WSL2中更新Python到最新版本(3.12.2)?

从嵌套的yaml创建一个嵌套字符串,后面跟着点

如何在Pyplot表中舍入值

使用__json__的 pyramid 在客户端返回意外格式

如何使用matplotlib查看并列直方图

利用SCIPY沿第一轴对数组进行内插

递归链表反转与打印语句挂起

Match-Case构造中的对象可调用性测试

我怎样才能让深度测试在OpenGL中使用Python和PyGame呢?

用LAKEF划分实木地板AWS Wrangler

如何通过函数的强式路径动态导入函数?

这是什么排序算法?(将迭代器与自身合并&&Q;)

用考克斯回归的生存分析系列的真值是模棱两可的.