Python TypeError:\uuuu init\uuuuuuu()接受1个位置参数,但给出了2个,通知bot用于不一致
我的bot在运行命令和idk时出现问题,为什么它一直给我这个错误,我使用的bot是为了发布discord,所以我在bot中使用的代码如下:Python TypeError:\uuuu init\uuuuuuu()接受1个位置参数,但给出了2个,通知bot用于不一致,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,我的bot在运行命令和idk时出现问题,为什么它一直给我这个错误,我使用的bot是为了发布discord,所以我在bot中使用的代码如下: import discord from discord.ext import commands from discord.ext.commands import Bot import asyncio import time from discord.ext.commands import has_permissions client = commands.
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import time
from discord.ext.commands import has_permissions
client = commands.Bot(command_prefix = "+")
client.remove_command("help")
@client.event
async def on_ready():
print(client.user.name)
print("Online")
print("-------")
@client.command(pass_context=True)
async def announce(ctx,*,message):
embed = discord.Embed("Information",description=message,color=0x9200ea)
embed.set_footer(text="Made by Elanovic#7940")
await client.send_message(ctx.message.channel,embed=embed)
client.run("TOKEN")
这是我从命令中得到的错误:
Ignoring exception in command announce:
Traceback (most recent call last):
File "C:\Users\Hasanfox69\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\Hasanfox69\Desktop\PYTHON\bot.py", line 19, in announce
embed = discord.Embed("Information",description=message,color=0x9200ea)
TypeError: __init__() 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 "C:\Users\Hasanfox69\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\Hasanfox69\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\Hasanfox69\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: TypeError: __init__() takes 1 positional argument but 2 were given
所有这些都发生在cmd中,bot通过命令+annound
从discord频道接收命令
但是bot会在cmd中响应上面的命令。代码中的错误是一个简单命令的属性错误 嵌入的语法为:
discord.Embed(Name="Embed", description='This is an EMBED', color=0xff00ff)
代码中的错误在哪里?
错误在嵌入代码中,也可以在回溯中看到
embed = discord.Embed("Information",description=message,color=0x9200ea)
您必须尝试输入嵌入的名称,但没有正确写入
因此,我只想说,将这一行更改为:
discord.Embed(name='Information', description=message, color=0x9200ea)
这将彻底解决你的问题
最后,我给你一个简单的建议。始终检查错误的回溯。在回溯中,您可以看到:
1.File "C:\Users\Hasanfox69\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
2. ret = await coro(*args, **kwargs)
3. File "C:\Users\Hasanfox69\Desktop\PYTHON\bot.py", line 19, in announce
4. embed = discord.Embed("Information",description=message,color=0x9200ea)
TypeError: __init__() takes 1 positional argument but 2 were given
第4行(根据我的标记)显示错误在嵌入代码中,因此您只需知道它来自何处,就可以简单地解决它
我很高兴能帮上忙。请随时询问您是否还有任何问题。:)
谢谢Ddiscord.Embed的参数不接受字符串作为第一个参数,并且列出的属性名称是color,而不是color