问题描述
我有一个discord机器人,它通过在随机频道中应答来响应消息。有时,它会随机选择一个没有权限发送消息的通道,这会引发错误。
这是我一直在处理此错误的方式:
try:
if message.content == "!xd":
guild = client.guilds[0]
random_xd = random.choice(random_list)
await random.choice(guild.text_channels).send(random_xd)
except discord.errors.Forbidden:
print("\nsomething went wrong\n")
if message.content == "!xd":
guild = client.guilds[0]
random_xd = random.choice(random_list)
await random.choice(guild.text_channels).send(random_xd)
有时,漫游器会将消息发送到其多次没有权限的频道。如何使其运行此代码块,直到最终发送消息?
解决方法
我不太清楚您的问题,但我会尽力回答。首先,据我所知,错误处理不适用于export const CValidEbookTypes = ['epub','mobi','pdf','azw3','txt','rtf'] as const;
export type IEbookType = typeof CValidEbookTypes[number];
// IEbookType will be "epub" | "mobi" | "pdf" | "azw3" | "txt" | "rtf"
,因此应使用try-except
事件。像这样:
on_command_error
这必须对您有用。