python - 如何在 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 的版本,但我不确定。
解决方案
您定义了嵌入,embedVar
因此您需要在发送消息时将其传入。此外,由于您已经在使用message.channel.send
,因此该message.channel
参数将毫无用处。
await message.channel.send(embed=embedVar)
推荐阅读
- python - Cythonize 具有复杂数组的 C 函数
- swift - Swift:当应用程序处于非活动状态时,willPresent 通知完成处理程序不起作用
- sql - SQL为每个不同的zone_id选择多个最大日期,其中帐户可能相同
- spring-boot - 如何从 Postman 上传图片
- javascript - 仅在选择选项填充选择元素时才能使GetSelected -Currency仅运行
- javascript - 如何使用 javascript 创建选项元素并设置它的值
- postgresql-9.6 - pg_restore FATAL:由于协议同步丢失而终止连接
- ios - 我的 Ionic 应用程序无法在 iOS 10.3.3 上的 iPhone 5 上打开
- reactjs - DraftJS 持久化数据并控制渲染块中的数据
- sql-server - 错误消息 102,级别 15 我的表别名有问题