【发布时间】:2021-03-22 19:24:05
【问题描述】:
就上下文而言,我与我自己和我的朋友一起为服务器创建了一个不和谐机器人。
我希望这个机器人做的部分事情是能够复制频道中的所有消息以进行备份,因为某些频道包含我们不想丢失的东西。
我已经得到它来复制消息,但它在连续复制许多消息时遇到问题。
代码如下:
@client.command()
async def MessageCopy(ctx, comeFrom, goTo):
attachments = []
aafile = None
fromChannel = client.get_channel(int(comeFrom))
toChannel = client.get_channel(int(goTo))
async for message in fromChannel.history(oldest_first=True, limit=None):
if not message.attachments == None:
for file in message.attachments:
aafile = await file.to_file()
attachments.append(aafile)
try:
await toChannel.send(content=message.clean_content, file=aafile)
except:
continue
attachments = []
aafile = None
客户端定义为
commands.Bot(command_prefix="$", case_insensitive=True)
机器人每次都被同一条消息捕获,消息没有什么特别之处,它不会抛出错误,它只是安静地停止复制。如果这很重要,那就是它无法复制的频道中的第 9639 条消息。
编辑:我通过它运行了另一个频道,它再次安静地停止,这次是第 9758 条消息。
【问题讨论】:
标签: python discord.py