首页 > 解决方案 > 如何在 discord.py 模块中添加嵌入

问题描述

我正在使用replit,这是我到目前为止的代码:

TOKEN = os.environ['TOKEN']
client = discord.Client()

@client.event
async def on_ready():
    print("bot online") 
    

@client.event
async def on_message(message):
  if message.content == "!Help":
    embedVar = discord.Embed(title="Title", description="Desc", color=0x00ff00)
    embedVar.add_field(name="Field1", value="hi", inline=False)
    embedVar.add_field(name="Field2", value="hi2", inline=False)
    await message.channel.send(message.channel, Embed=embed)



client.run(TOKEN)

它返回一条错误消息,指出“嵌入”未定义。我只是复制了这个网站,找了一个小时后,所以我不太了解,所以如果有人可以向我解释如何解决这个问题以及如何使用嵌入 ID 来欣赏它。我想我是低于 1 的版本,但我不确定。

标签: pythondiscorddiscord.py

解决方案


您定义了嵌入,embedVar因此您需要在发送消息时将其传入。此外,由于您已经在使用message.channel.send,因此该message.channel参数将毫无用处。

await message.channel.send(embed=embedVar)

推荐阅读