简体   繁体   English

如何在 Pycord 中修复“AttributeError:'TextChannel' 对象没有属性'news'”?

[英]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

I think you should upgrade your pycord to development version.我认为你应该将你的 pycord 升级到开发版本。

pip install -U git+https://github.com/Pycord-Development/pycord

It seems that in this commit , they've added the news attribute.似乎在这个commit中,他们添加了news属性。

暂无
暂无

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

相关问题 如何修复此 AttributeError: 'SubRequest' object 没有属性 'getfuncargvalue'? - How do I fix this AttributeError: 'SubRequest' object has no attribute 'getfuncargvalue'? 我该如何解决这个 AttributeError: 'NoneType' object has no attribute 'text'? - How do i fix this AttributeError: 'NoneType' object has no attribute 'text'? 如何修复 AttributeError: &#39;bytes&#39; object has no attribute &#39;encode&#39;? - How do I fix AttributeError: 'bytes' object has no attribute 'encode'? 如何修复 AttributeError: 'NoneType' object 没有属性 'lower'? - How do i fix AttributeError: 'NoneType' object has no attribute 'lower'? 我收到一条错误消息,指出 AttributeError: &#39;str&#39; object has no attribute &#39;read&#39;,我不知道如何修复它 - I'm getting an error that says AttributeError: 'str' object has no attribute 'read' and i do not know how to fix it 我该如何修复,AttributeError: 'NoneType' 对象没有属性 'send' - How can I fix, AttributeError: 'NoneType' object has no attribute 'send' 如何解决错误“ AttributeError:&#39;pygame.Surface&#39;对象没有属性&#39;units&#39;”? - How do I fix the error “AttributeError: 'pygame.Surface' object has no attribute 'units'”? AttributeError:“ tuple”对象没有属性“ append”是什么,如何修复我的代码? - What does AttributeError: 'tuple' object has no attribute 'append' and how do I fix my code? 尝试使用 moviepy 编写 CompositeVideoClip 时,如何修复“AttributeError:‘NoneType’对象没有属性‘stdout’”? - How do I fix "AttributeError: 'NoneType' object has no attribute 'stdout'" when trying to write a CompositeVideoClip with moviepy? AttributeError: &#39;int&#39; 对象没有属性 &#39;get&#39; 我该如何修复它 - AttributeError: 'int' object has no attribute 'get' how can i fix it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM