【发布时间】:2021-01-08 17:48:54
【问题描述】:
我有一些代码基本上只是从命令中获取 arg 并在 if 语句中将其与一些文本进行比较。我不知道为什么,但是当它尝试将 arg 保存到变量时,我不断收到此错误:
Ignoring exception in command raceinfo:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\User\Desktop\DiscordMMO\Scripts\Character_Creator.py", line 66, in some_crazy_function_name
raceInfo = ctx.arg
AttributeError: 'Context' object has no attribute 'arg'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\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: AttributeError: 'Context' object has no attribute 'arg'
这是代码的sn-p:
@bot.command(name="raceinfo")
async def some_crazy_function_name(ctx, arg):
raceInfo = ctx.arg
if raceInfo == "Human" or "human":
【问题讨论】:
-
您可以尝试添加您当前拥有的代码吗?这将使您更容易使用它来帮助您。
-
能否请您添加一段实际的代码?
-
对不起,忘记添加代码,现在添加它
-
嗯,这个错误是不言自明的。
ctx内部没有元素arg。 -
AttributeError: 'Context' object has no attribute 'arg'似乎对您来说应该是不言自明的,并且对于其他对相关对象一无所知的人来说完全不透明。
标签: python python-3.x discord.py