就上下文而言,我为服务器创建了一个与我自己和我的朋友不和谐的机器人。
我希望这个机器人所做的部分是为了备份,能够在一个通道中复制所有的消息,因为有些通道有我们永远不想丢失的东西。
我已经将它用于复制消息,但它在连续复制多条消息时遇到了问题。
下面是代码:
@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消息上。
发布于 2020-12-11 23:59:33
我找到了解决办法。
结果可能是
aafile = file.to_file()这会导致它停止复制,代码会导致错误,它会悄悄地停止。
因此,我将代码修改为:
for file in message.attachments:
try:
aafile = file.to_file()
attachments.append(aafile)
except:
continuehttps://stackoverflow.com/questions/65250321
复制相似问题