简体   繁体   English

公会上的 Pycord message.content 空白

[英]Pycord message.content blank on guilds

I want to develop a discord bot.我想开发一个 discord 机器人。 After trying the bot on my Raspberry Pi, I cannot read messages of the bot on the guilds.在我的 Raspberry Pi 上尝试了该机器人后,我无法在公会上阅读该机器人的消息。 On the Raspberry Pi the program is working without any problems.在 Raspberry Pi 上,该程序运行正常,没有任何问题。 Obviously I turned the pi off before starting the bot.显然我在启动机器人之前关闭了 pi。 I already tried kicking and reconnecting the bot on the servers, but that didn`t work.我已经尝试在服务器上踢并重新连接机器人,但这没有用。 Private messages to the bot are running smoothly.发送给机器人的私人消息运行顺利。 The messages are blank, so the event is called, but nothing is printed to the command line.消息是空白的,因此会调用事件,但不会将任何内容打印到命令行。

import discord
from discord.ext import commands

bot = commands.Bot()

@bot.event
async def on_message(message):
    print(message.content)

bot.run("TOKEN")

The content of the message variable is (I have changed the ids and some other variables): message 变量的内容是(我已经更改了 ids 和其他一些变量):

<Message id=953328581969116272 channel=<TextChannel id=956654537448771667 name='general' position=0 nsfw=False news=False category_id=953322537446663665> type=<MessageType.default: 0> author=<Member id=689200156665367842 name='my_name' discriminator='0000' bot=False nick=None guild=<Guild id=953322535556471664 name='Test' shard_id=0 chunked=False member_count=2>> flags=<MessageFlags value=0>>

I`ve found an open github problem, but because discord.py is not continued I have to ask it here.我发现了一个开放的github问题,但是因为discord.py没有继续我不得不在这里问。 (The link: https://github.com/Rapptz/discord.py/issues/6820 ) (链接: https://github.com/Rapptz/discord.py/issues/6820

Switching back to API version 9 has solved the issue for me.切换回API 版本 9为我解决了这个问题。

I've encountered the same issue and found the solution in the official Pycord Discord.我也遇到过同样的问题,在官方的 Pycord Discord 中找到了解决方法。 They have switched to the Discord API version 10 where message content has become a privileged intent in accordance with the new upcoming Discord changes (Message Content: Privileged Intent for Verified Bots ).他们已切换到 Discord API 版本 10 ,根据即将到来的新 Discord 更改(消息内容已验证),消息内容已成为特权意图。

In short, if your bot is in more than 75 servers you will need to verify it in order to access privileged intents.简而言之,如果您的机器人位于超过 75 台服务器中,您将需要对其进行验证才能访问特权意图。

Here's Pycord's detailed post for reference这是 Pycord 的详细帖子供参考

Dated 20/03/2022日期为 20/03/2022

Hello @v2.0 Testers, Along with https://github.com/Pycord-Development/pycord/pull/1012 , pycord has switched to API version 10. This version introduces a new privileged intent: message content. @v2.0 测试人员您好,随着https://github.com/Pycord-Development/pycord/pull/1012 ,pycord 已切换到 API 版本 10。此版本引入了新的特权意图:消息内容。 Bots that use the master branch of pycord need to turn this intent on in order to receive message contents and invoke prefixed commands.使用 pycord 主分支的机器人需要打开此意图,以便接收消息内容并调用前缀命令。 However if you don't want to switch to v10, you can change the API version back to 9 ( https://github.com/Pycord-Development/pycord/pull/1032 )但是,如果您不想切换到 v10,您可以将 API 版本改回 9( https://github.com/Pycord-Development/pycord/pull/1032

Turn the intent on:打开意图:

 bot = commands.Bot(..., intents=discord.Intents(message_content=True))

Switch back to API version 9:切换回 API 版本 9:

 discord.http.API_VERSION = 9 bot = commands.Bot(...)

Seehttps://support-dev.discord.com/hc/en-us/articles/4404772028055 for more information about the intent.有关意图的更多信息,请参阅https://support-dev.discord.com/hc/en-us/articles/4404772028055

This is the link to their Discord server.这是他们的 Discord 服务器的链接。 I would have not found the solution without being part of it.如果不参与其中,我就不会找到解决方案。 https://discord.gg/sb5zZYnz https://discord.gg/sb5zZYnz

Discord.py is back to development again, you should use it. Discord.py 又恢复开发了,你应该使用它。 You can ask these question in the discord.py Discord server and get quick response other than asking it at here!您可以在 discord.py Discord 服务器中询问这些问题,并获得快速响应,而不是在这里询问!

Have fun coding!玩得开心编码!

在此处输入图像描述

From October 25, 2021, accessing message content now requires enabling a new privilege intent.从 2021 年 10 月 25 日起,现在访问消息内容需要启用新的权限意图。

Head to your developer portal and do this.前往您的开发者门户并执行此操作。

Applications ↦ Settings ↦ Bot ↦ Privileged Gateway Intents应用程序↦设置↦机器人↦特权网关意图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM