我正试图发表一个不和谐的声明:
但是,我一直收到一个错误:the error
我试图完成的是制作一个公告机器人,这样当频道中的用户执行.announce <text>
操作时,它会向特定频道发送一个嵌入,如下所示:https://prnt.sc/rgw4yc
async def announce(ctx, message : str):
try:
for chan in channels:
try:
channel = bot.get_channel(channel id)
info = discord.Embed(title="New Announcement!", description=str(message), color=0xFFFFFF)
await channel.send(embed=info)
try:
except Exception as e:
await ctx.send(e)
await ctx.send("Error: " + str(chan))
except Exception as e:
await ctx.send(e) ```
基于error
错误出现在代码的以下部分
除了在try循环中,您不能使用。逻辑流程如下 如果失败,请尝试执行一个操作以引发异常,这样可以防止整个代码失败
范例
在上面的示例中,如果变量
some_url
有错误的URL或站点关闭,它将打印请求失败并继续执行其余代码相关问题 更多 >
编程相关推荐