简体   繁体   中英

How do you get a message from a channel?

channel = bot.get_channel(id_of_the_channel)
message = await channel.fetch_message(id_of_the_message)

I tried to use this code so that a bot could edit its own message, but there's an error on the line with "fetch_message".

File "main.py", line 280, in on_message message = await channel.fetch_message(messageid) AttributeError: 'NoneType' object has no attribute 'fetch_message'

So get_channel only returns the channel object if it's in the cache - if it's returning None then it's not. It is returning None as per the error message. To fix:

channel = await bot.fetch_channel(id_of_the_channel)
message = await channel.fetch_message(id_of_the_message)

This should resolve that issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM