【发布时间】:2020-12-02 13:26:44
【问题描述】:
在 discord.py 中,我有一个 @tasks.loop,它每 10 秒运行一次。它通过channel.fetch_message(message-id) 获取消息并将其从hi 编辑为hello。再过 10 秒后,它会将消息更改回 hi。起初它正常工作。但是,当机器人自动重启时,它无法获取消息。我该如何解决这个问题?
【问题讨论】:
标签: python discord discord.py
在 discord.py 中,我有一个 @tasks.loop,它每 10 秒运行一次。它通过channel.fetch_message(message-id) 获取消息并将其从hi 编辑为hello。再过 10 秒后,它会将消息更改回 hi。起初它正常工作。但是,当机器人自动重启时,它无法获取消息。我该如何解决这个问题?
【问题讨论】:
标签: python discord discord.py
commands.Bot 没有 fetch_message 属性,只有 abc.Messageable 有。要获取消息,首先需要获取消息发送到的通道,然后获取它。
# Getting the channel
channel = bot.get_channel(id_here)
# if you want a faster way:
channel = Guild.get_channel(id_here)
# Getting the message
message = await channel.fetch_message(id_here)
【讨论】: