【问题标题】:"edit() takes 1 positional argument but 2 were given" Even though I only gave one. [Discord.PY]“edit() 接受 1 个位置参数,但给出了 2 个”即使我只给了一个。 [不和谐.PY]
【发布时间】:2021-07-05 20:44:46
【问题描述】:

所以,我正在为 Discord Bot 编写一个 hack 命令(显然是个笑话),但我遇到了一个奇怪的错误。意思是我给出了一个只需要 1 个位置参数的东西,却给出了 2 个参数,即使它显然不是。

@client.command()
async def hack(message, member:discord.Member):
  message = await message.reply("**It's info yoinking time!**\nHacking "+member.name+"\n\n**This command is currently only proof-of-concept and does not work past finding password. Slend is working on a fix.**")

  await asyncio.sleep(3)

  await message.edit(content="**1/5** | Finding e-mail address...")

  await asyncio.sleep(3)

  await message.edit(content="**1/5** | E-mail address found: `"+member.name+"@discord.com`")

  await asyncio.sleep(2)

  await message.edit(content="**2/5** | Finding password to Discord Account...")

  await asyncio.sleep(3)

  await message.edit(content="**2/5** | Discord Account password found: `me("+member.name+")iscool"+member.discriminator+"`")

  await asyncio.sleep(2)

  await message.edit("**3/5** | Logging in to Discord Account...")

这是我的错误:

Ignoring exception in command hack:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 107, in hack
    await message.edit("**3/5** | Logging in to Discord Account...")
TypeError: edit() takes 1 positional argument but 2 were given

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/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: TypeError: edit() takes 1 positional argument but 2 were given

我不确定它为什么这么说,正如你所看到的,我确实只给出了一个论点。 如果这有帮助,它会在绑定编辑 from **2/5** | Discord Account password found: `me("+member.name+")iscool"+member.discriminator+" to **3/5** | Logging in to Discord Account...

时引发此错误

感谢您的帮助! :D

【问题讨论】:

标签: python python-3.x discord.py


【解决方案1】:

你的最后一行是错误的,content 是一个关键字参数

await message.edit(content="**3/5** | Logging in to Discord Account...")

我不确定你为什么上次做错了,之前的尝试都做对了。

【讨论】:

  • 我不太确定那里有什么不同,但是根据您所说的“您的最后一行错误”这一事实,我只是复制了前面的一行并进行了更改说了什么。出于这个原因,你会得到那个勾号。
  • 您将字符串作为位置参数传递,message.edit 只接受关键字参数。
猜你喜欢
  • 2016-10-13
  • 2019-04-20
  • 2018-11-15
  • 2014-07-19
  • 2016-08-09
  • 2020-01-30
  • 2019-08-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多