我做了一个狙击命令,但唯一的问题是它没有正确提及用户。我一直试图解决这个问题这么久。我还附上了一张狙击手的样子的照片。 追溯错误:
忽略命令 snipe 中的异常:
回溯(最近一次调用最后一次):
文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第85行,包裹
ret = await coro(*args, **kwargs)
文件“main.py”,第 261 行,在 snipe 中
embed = discord.Embed('description = f"<@!{snipe_message_author} 已删除 {snipe_message_content}
')
类型错误:init() 需要 1 个位置参数,但给出了 2 个
上述异常是以下异常的直接原因:
回溯(最近一次调用最后一次):
文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py”,第 939 行,在调用中
等待 ctx.command.invoke(ctx)
文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第 863 行,在调用中
等待注入(*ctx.args,**ctx.kwargs)
文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第 94 行,包装好的
从 exc 引发 CommandInvokeError(exc)
discord.ext.commands.errors.CommandInvokeError:命令引发异常:TypeError:init() 需要 1 个位置参数,但给出了 2 个
smc = []
sma = []
snipe_message_content = None
snipe_message_author = None
snipe_message_id = None
@client.event
async def on_message_delete(message):
global snipe_message_content
global snipe_message_author
global snipe_message_id
snipe_message_content = message.content
snipe_message_author = message.author.id
snipe_message_id = message.id
await asyncio.sleep(60)
if message.id == snipe_message_id:
snipe_message_author = None
snipe_message_content = None
snipe_message_id = None
@client.command()
async def snipe(message):
if snipe_message_content==None:
await message.channel.send("Theres nothing to snipe.")
else:
embed = discord.Embed(description=f"{snipe_message_content}")
embed.set_footer(text=f"Asked by {message.author.name}#{message.author.discriminator}", icon_url=message.author.avatar_url)
embed.set_author(name= f"<@!{snipe_message_author}>")
await message.channel.send(embed=embed)
return
答案 0 :(得分:1)
您不能在作者字段或标题字段中提及用户,最好将其移至描述。
embed = discord.Embed(description = f"<@!{snipe_message_author}> deleted `{snipe_message_content}`")