discord.py TypeError:send()接受1到2个位置参数,但给出了3个



每次运行此代码时,我都会收到错误消息,如有任何帮助,我们将不胜感激我使用带有visualstudio代码的python 3.8。我是编码新手,所以如果答案很明显,我真的很抱歉,但提前感谢你!

代码:

while True:
difficulty_setting = 2
difficulty_progression = math.floor(score/10)
overall_difficulty = difficulty_setting + difficulty_progression
numbers_list = []
for x in range(overall_difficulty):
value = random.randint(1,9)
numbers_list.append(value)
answer = functools.reduce(operator.mul, numbers_list, 1)
await ctx.send('Multiply these numbers', numbers_list)
guess = int(input())
if guess == answer:
score = score + (1 * overall_difficulty)
continue
else:
await ctx.send('Game over! The answer was', answer)
elapsed_time = time.time() - start_time
await ctx.send('Score:', score, 'Time', elapsed_time)
break

错误消息:

Traceback (most recent call last):
File "C:UsersRESUTHERAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandsbot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:UsersRESUTHERAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 855, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:UsersRESUTHERAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: send() takes from 1 to 2 positional arguments but 3 were given

您正试图像使用print一样使用sendprint允许您将要用逗号按顺序打印的内容链接在一起,但发送需要一个字符串。

例如await ctx.send('Game over! The answer was', answer)

应为:

await ctx.send(f'Game over! The answer was {answer}')

与其他发送呼叫相同。

最新更新