[英]How do I fix "AttributeError: 'TextChannel' object has no attribute 'news'" in Pycord?
I have recently started using Pycord to make a Discord bot.我最近开始使用Pycord制作一个 Discord 机器人。 However, I have quickly run into an error that I'm not sure how to deal with.
但是,我很快遇到了一个我不知道如何处理的错误。
Here is my code:这是我的代码:
import discord
bot = discord.Bot(debug_guilds=[<my guild ID>])
@bot.event
async def on_ready():
print(f'Logged in as {bot.user}!')
@bot.event
async def on_message(message: discord.Message):
print(message)
bot.run('token')
Here is the error:这是错误:
Ignoring exception in on_message
Traceback (most recent call last):
File "c:\Users\Username\Desktop\DiscordBot\env\lib\site-packages\discord\client.py", line 382, in _run_event
await coro(*args, **kwargs)
File "c:/Users/Username/Desktop/DiscordBot/main.py", line 18, in on_message
print(message)
File "c:\Users\Username\Desktop\DiscordBot\env\lib\site-packages\discord\message.py", line 777, in __repr__
return f"<{name} id={self.id} channel={self.channel!r} type={self.type!r} author={self.author!r} flags={self.flags!r}>"
File "c:\Users\Username\Desktop\DiscordBot\env\lib\site-packages\discord\channel.py", line 190, in __repr__
attrs = [(val, getattr(self, val)) for val in self._repr_attrs]
File "c:\Users\Username\Desktop\DiscordBot\env\lib\site-packages\discord\channel.py", line 190, in <listcomp>
attrs = [(val, getattr(self, val)) for val in self._repr_attrs]
AttributeError: 'TextChannel' object has no attribute 'news'
I'm not sure why this error occurs because, to my knowledge, the TextChannel
object does not have the attribute " news
".我不确定为什么会发生此错误,因为据我所知,
TextChannel
对象没有属性“ news
”。 The closest thing I could find is is_news()
.我能找到的最接近的是
is_news()
。
Checklist:清单:
Checked for duplicate questions.检查重复的问题。
Checked Pycord API reference for on_message
.检查了 on_message 的
on_message
API 参考。
Attempted to print just the message content
instead of the message
object.试图只打印消息
content
而不是message
对象。
Checked intent issues by confirming that Message Intent
is enabled on the Discord Developer Portal .通过确认在Discord Developer Portal上启用了
Message Intent
来检查意图问题。
Environment Information:环境信息:
OS: Windows 7操作系统:Windows 7
Python Version: 3.8.10 (Stuck on this version because Python 3.9 and up no longer supports Windows 7) Python 版本:3.8.10(停留在这个版本上,因为 Python 3.9 及更高版本不再支持 Windows 7)
Python Virtual Environment Name: env Python 虚拟环境名称:env
Pycord Version: 2.0.0rc1 Pycord 版本:2.0.0rc1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.