【问题标题】:printing bot messages discord.py打印机器人消息 discord.py
【发布时间】:2022-05-13 10:27:14
【问题描述】:

discord.py 有什么变化吗? 从昨天开始,我的机器人就不能工作了。

当另一个机器人写一些东西时,他们应该提到某人

async def on_message(message):
    if message.author.id == 123456789: #any bot ID
        if message.content.startswith(
            "Alright"): #message
            await message.channel.send("<@123213213321231> look") 
print("Done")

我尝试打印来自特定频道的消息以查看机器人消息是否有任何变化,但我什至无法打印它们..

async def on_message(message):
    if message.channel.id == 123456789:
        print(message.content)

例如,Carlbot - 它打印我的消息,但 carlbot 消息是空格...

abc
!lock

!unlock

?remindme 1min blahblah

我没有改变它工作了一个多月的任何东西,突然它没有,我不知道为什么。

【问题讨论】:

  • 你在使用自我机器人吗?

标签: python printing discord.py bots


【解决方案1】:

您是否启用了意图?

(来自 d.py 服务器!)

什么是意图?

自 2020 年 10 月 28 日起,Discord 要求用户声明他们的机器人运行需要哪些类型的信息(即事件)。 这是以意图的形式完成的。 您可以在此处阅读有关意图的更多信息:https://discordpy.readthedocs.io/en/latest/intents.html

默认情况下,某些意图(例如成员和状态)被禁用,因为它们被称为特权。这意味着您需要采取一些额外的步骤来支持它们。 在此处阅读特权意图:https://discordpy.readthedocs.io/en/latest/intents.html#privileged-intents

如果您在代码中使用 on_member_* 事件,如果不进行更改,您的机器人将无法再运行!

如何启用它们的步骤:

1 - 在代码中

intents = discord.Intents.default()
intents.members = True  
bot = commands.Bot(command_prefix=...., intents=intents)

2 - 在不和谐开发者门户上 应用程序 > yourApplication > bot > 向下滚动然后检查这些https://imgur.com/a/oE7LrIa(只有你需要的!)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    相关资源
    最近更新 更多