Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I fix "AttributeError: 'TextChannel' object has no attribute 'news'" in Pycord?

I have recently started using Pycord to make a Discord bot. 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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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". The closest thing I could find is is_news().

Checklist:

Checked for duplicate questions.
Checked Pycord API reference for on_message.
Attempted to print just the message content instead of the message object.
Checked intent issues by confirming that Message Intent is enabled on the Discord Developer Portal.

Environment Information:

OS: Windows 7
Python Version: 3.8.10 (Stuck on this version because Python 3.9 and up no longer supports Windows 7)
Python Virtual Environment Name: env
Pycord Version: 2.0.0rc1

>Solution :

I think you should upgrade your pycord to development version.

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

It seems that in this commit, they’ve added the news attribute.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading