How do I fix "AttributeError: 'TextChannel' object has no attribute 'news'" in Pycord?
How do I fix "AttributeError: 'TextChannel' object has no attribute 'news'" in Pycord?
我最近开始使用 Pycord 制作 Discord 机器人。但是,我很快 运行 遇到了一个我不确定如何处理的错误。
这是我的代码:
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')
错误如下:
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'
我不确定为什么会出现此错误,因为据我所知,TextChannel
object does not have the attribute "news
". The closest thing I could find is is_news()
.
清单:
已检查重复问题。
检查 Pycord API reference for on_message
.
试图仅打印消息 content
instead of the message
对象。
通过确认在 Discord Developer Portal.
上启用了 Message Intent
检查了意图问题
环境信息:
OS: Windows 7
Python 版本:3.8.10(因为 Python 3.9 及更高版本不再支持 Windows 7,所以卡在这个版本上)
Python 虚拟环境名称:env
Pycord 版本:2.0.0rc1
我认为你应该将你的 pycord 升级到开发版本。
pip install -U git+https://github.com/Pycord-Development/pycord
似乎在这个 commit 中,他们添加了 news
属性。
我最近开始使用 Pycord 制作 Discord 机器人。但是,我很快 运行 遇到了一个我不确定如何处理的错误。
这是我的代码:
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')
错误如下:
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'
我不确定为什么会出现此错误,因为据我所知,TextChannel
object does not have the attribute "news
". The closest thing I could find is is_news()
.
清单:
已检查重复问题。
检查 Pycord API reference for on_message
.
试图仅打印消息 content
instead of the message
对象。
通过确认在 Discord Developer Portal.
Message Intent
检查了意图问题
环境信息:
OS: Windows 7
Python 版本:3.8.10(因为 Python 3.9 及更高版本不再支持 Windows 7,所以卡在这个版本上)
Python 虚拟环境名称:env
Pycord 版本:2.0.0rc1
我认为你应该将你的 pycord 升级到开发版本。
pip install -U git+https://github.com/Pycord-Development/pycord
似乎在这个 commit 中,他们添加了 news
属性。