【问题标题】:How do I send embeds using interactions.py?如何使用 interactions.py 发送嵌入?
【发布时间】:2023-01-22 22:45:05
【问题描述】:

我一直在尝试发送一个带有 interactions.py 的嵌入,这是对 discord.py 的重写(据我所知)。但是,它不会像在 discord.py 中那样工作。

这是错误的代码:

@client.command(
name="embed",
description="Test",
scope=[993586870606905404],
)
async def embed(ctx: interactions.CommandContext):
embed = discord.Embed(
  title="your title",
  description="your description",
  color=discord.Color.random(),
  timestamp=datetime.datetime.now())
await ctx.send(embed=embed)

但是,我不断收到以下错误:

Traceback (most recent call last):
File "/Users/my.computer/bot.py/main.py", line 79, in embed
  await ctx.send(embed=embed)
File "/Users/my.computer/venv/lib/python3.10/site-packages/interactions/client/context.py", line 445, in send
  payload = await super().send(content, **kwargs)
TypeError: _Context.send() got an unexpected keyword argument 'embed'

请帮我解决这个问题!我无法在互联网上的任何地方找到答案。

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    更新:由于乐于助人的员工,我去了不和谐并找到了答案。

    对于遇到此问题的其他人:

    这段代码对我有用:

    @client.command(
    name="embed",
    description="Test",
    scope=[993586870606905404],
    )
    async def embed(ctx: interactions.CommandContext):
    embed = discord.Embed(
      title="your title",
      description="your description",
      color=discord.Color().green,
      timestamp=datetime.datetime.now())
    await ctx.send(embeds=embed)
    

    【讨论】:

      【解决方案2】:

      您必须更改嵌入的名称或命令的名称,并使用未嵌入的嵌入来等待 ctx.send(embeds=...)

      @client.command(
      name="embed",
      description="Test",
      scope=[993586870606905404],
      )
      async def embed(ctx: interactions.CommandContext):
      embed_message = discord.Embed(
        title="your title",
        description="your description",
        color=discord.Color().green,
        timestamp=datetime.datetime.now())
      await ctx.send(embeds=embed_message)
      

      【讨论】:

        猜你喜欢
        • 2022-11-28
        • 2022-08-14
        • 2019-01-15
        • 2021-10-22
        • 2020-11-04
        • 2020-10-11
        • 1970-01-01
        • 1970-01-01
        • 2021-01-25
        相关资源
        最近更新 更多