![](/img/trans.png)
[英]How do I fix this AttributeError: 'SubRequest' object has no attribute 'getfuncargvalue'?
[英]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
对象没有属性“ news
”。 我能找到的最接近的是is_news()
。
清单:
检查重复的问题。
检查了 on_message 的on_message
API 参考。
试图只打印消息content
而不是message
对象。
通过确认在Discord Developer Portal上启用了Message Intent
来检查意图问题。
环境信息:
操作系统: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
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.