【问题标题】:how can i code discord bot to delete "user pinned a message" message?我如何编码不和谐机器人以删除“用户固定消息”消息?
【发布时间】:2021-10-03 22:51:37
【问题描述】:

我尝试使用 python 为我的 discord 机器人进行编码,以自动删除“用户将消息固定到此频道...”消息,每次有人将消息固定到频道但它不起作用,我不知道为什么:(可以的话请帮忙?tysm

我的问题: 机器人不会删除“用户消息固定到此频道。查看所有固定消息。”我固定消息时的消息

这是我的代码:我尝试了什么:v

if message.type == "PINS_ADD" and message.author.bot: 
   await message.delete()

我做错了什么? 我必须补充一点,我是初学者所以-

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    message.author.bot 仅当消息是由 Bot 自己编写时才为 True。由于您要删除的消息是系统消息,因此并非如此

    只需删除它,它应该可以工作

    if message.type is discord.MessageType.pins_add:
       await message.delete()
    
    # or i think this would also work
    if str(message.type) == "pins_add"
        await message.delete()
    

    【讨论】:

    • Message.type 返回一个MessageType 实例,你不能真正将它与字符串进行比较,if message.type is discord.MessageType.pins_add: 应该可以工作。
    • 好吧,这是有道理的,但我将代码更改为if discord.MessageType.pins_add: await message.delete(),机器人会删除发送的每条消息,而不是固定的@ŁukaszKwieciński
    • OHHH 等待 nvm 原谅我的小误会,我将其更改为 if message.type is discord.MessageType.pins_add: 并且它有效,谢谢 :) @ŁukaszKwieciński
    • 啊是的我忘了^^
    猜你喜欢
    • 2018-05-02
    • 2021-05-29
    • 2021-07-25
    • 1970-01-01
    • 2021-09-26
    • 2018-11-19
    • 1970-01-01
    • 2020-12-23
    • 2020-04-21
    相关资源
    最近更新 更多