简体   繁体   中英

Edit a message in a specific channel in Discord.py

(Discord.py)

I'm trying to make a "Status" message in a dedicated channel, this message will be affected by messages sent in other channels For this I need to select my message in said channel and then edit it

I've been looking around and trying stuff for about an hour now but I can't find anything that works, the closest I got is this:

status_msg = "Placeholder"
status_channel = client.get_channel(channelID)
status_message = status_channel.fetch_message(messageID)
await status_message.edit(content=status_msg)

With the error: AttributeError: 'coroutine' object has no attribute 'edit'

I believe I need a different editting command?

( I'm using @client.event and this needs to happen in async def on_message(message): )

You need to await the fetch_message function based on the docs .

status_msg = "Placeholder"
status_channel = client.get_channel(channelID)
status_message = await status_channel.fetch_message(messageID)
await status_message.edit(content=status_msg)

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