【问题标题】:Embed command Discord嵌入命令 Discord
【发布时间】:2021-02-05 07:08:50
【问题描述】:

想要嵌入此代码:

@bot.command(pass_contex = True)
async def Dragning(ctx, num):
    try:
        arg = random.randint(1, int(num))
    except ValueError:
        return await ctx.channel.send("Endast hela nummer")
    else:
        return await ctx.channel.send(str(arg))

尝试了所有我能找到的东西,比如:

@bot.command(pass_contex = True)
async def Dragning(ctx, num):
    embed = discord.Embed(title="Dragning")
    try:
        arg = random.randint(1, int(num))
    except ValueError:
        return await ctx.channel.send("Endast hela nummer")
    else:
        return await ctx.channel.send(str, embed=Embed(arg))

还有其他几种方法,谁能给我一些指点?

【问题讨论】:

  • 除了下面的答案,你也不需要添加pass_context = True,所以你可以说@bot.command(),它会起作用。

标签: discord discord.py


【解决方案1】:

你正在做的是ctx.send(embed=Embed(arg))。您应该要做的是发送您之前已经创建的嵌入实例,因此在您的情况下为ctx.send(embed=embed)。您应该将该值添加到嵌入中,而不是使用该值创建一个新的嵌入(这甚至不起作用)。

@bot.command()
async def Dragning(ctx, num):
    embed = discord.Embed(title="Dragning")
    try:
        arg = random.randint(1, int(num))
        embed.description = arg
    except ValueError:
        return await ctx.send("Endast hela nummer")
    else:
        return await ctx.send(embed=embed)

我将其添加到说明中,因为您没有提供字段标题或任何内容。您还可以将其添加为字段、页脚等。

API docs 中有关嵌入功能(字段、...)的更多信息。

另外,您可以只使用ctx.send() 而不是ctx.channel.send(),以及pass_context kwarg no longer exists,因此您应该从命令装饰器中删除它。现在自动传递上下文。

【讨论】:

  • 谢谢,现在我明白了:)
猜你喜欢
  • 2019-04-19
  • 2021-06-28
  • 1970-01-01
  • 1970-01-01
  • 2018-03-04
  • 2019-12-08
  • 2022-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多