python - 如何用 discord bot python 警告某人
问题描述
我试图用这个功能警告我的不和谐机器人的人:
async def warn(ctx, member : discord.Member=None, * , reason=None):
if member is None:
return await ctx.send("This user could not be found or you didnt't provide one :(")
if reason is None:
return await ctx.send("Woah Woah Woah. I'm not letting you ban a user for no reason! Please provide a reason.")
try:
first_warning = False
client.warnings[ctx.guild.id][member.id][0] += 1
client.warnings[ctx.guild.id][member.id][1].append((ctx.author.id, reason))
except KeyError:
first_warning = True
client.warnings[ctx.guild.id][member.id] = [1, [(ctx.author.id, reason)]]
count = client.warnings[ctx.guild.id][member.id][0]
await ctx.send(f"{member.mention} has {count} {'warning' if first_warning else 'warnings'}")
但它标记了这个回溯错误:
Ignoring exception in command warn:
Traceback (most recent call last):
File "C:\Users\josho\Documents\Stuuf\bot.py", line 31, in warn
client.warnings[ctx.guild.id][member.id][0] += 1
KeyError: 852609248352272414
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\***\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\***\Documents\Stuuf\bot.py", line 35, in warn
client.warnings[ctx.guild.id][member.id] = [1, [(ctx.author.id, reason)]]
KeyError: 852609248352272414
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\***\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\j****\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\j***\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 852609248352272414
请帮忙!每个人都拒绝了我。你是我唯一的希望!:)
解决方案
推荐阅读
- javascript - 获取要定期调用的函数
- apache-spark-sql - 借助 Spark-Sql 或 PySpark 使用两个表创建第三个表(不使用 Panda(Python))
- mysql - MySql 根据其他行选择行
- firebase - (Ionic 4)当应用程序处于前台时,无法使用 firebaseX 接收通知
- docker - 如果找不到链接容器,docker run 会导致“无法找到图像”
- wireshark - 如何在 PCAP 上应用中止过滤器?
- amazon-web-services - 如何使用 Cloud Formation 模板在 AWS Elastic Beanstalk 中包含粘性会话
- javascript - 窗口.打印();只打印一页
- linux - 在 linux 中使用 cd 更改当前目录的一部分
- python - 如何在 django 2.2 的 `django.contrib.admin.models.LogEntry` 中逐字获取 `get_change_message`