【问题标题】:snipe command isn't mentioning user狙击命令没有提到用户
【发布时间】:2021-07-29 09:27:04
【问题描述】:

我做了一个狙击命令,但唯一的问题是它没有正确提及用户。我一直在努力解决这个问题。我还附上了一张狙击手的照片。 回溯错误:

忽略命令狙击中的异常: 回溯(最近一次通话最后): 文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第 85 行,已包装 ret = 等待 coro(*args, **kwargs) 文件“main.py”,第 261 行,在狙击 embed = discord.Embed('description = f"{snipe_message_content}') TypeError: 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

【问题讨论】:

    标签: discord discord.py


    【解决方案1】:

    作者字段或标题字段不能提及用户,最好将其移至描述。

    embed = discord.Embed(description = f"<@!{snipe_message_author}> deleted `{snipe_message_content}`")
    

    【讨论】:

    • 我添加了新代码,但它给了我一个 pyflakes 错误 [pyflakes] 在扫描字符串文字时 EOL。我认为代码中一定有错字,所以我试图修复它。所以现在新代码是embed = discord.Embed('description = f"&lt;@!{snipe_message_author} deleted {snipe_message_content}')。在我测试它之后,它给了我一个巨大的回溯错误。由于篇幅太长,我会把它放在我原来的帖子里。
    • 已修复,来自 " 的错字
    • 我是否必须更改代码中的其他任何内容才能喜欢嵌入?因为现在它正在显示此图像。图片在原帖中。
    • 再次编辑,是的,您必须删除 set_author
    猜你喜欢
    • 2021-01-30
    • 2021-02-27
    • 1970-01-01
    • 2021-10-26
    • 2021-04-25
    • 2020-11-23
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    相关资源
    最近更新 更多