如何通过我的 Discord 机器人使用 /python 发送嵌入内容?

2023-11-23

我一直在开发一个新的 Discord 机器人。

我已经学到了一些东西,现在,我想让这些东西变得更加定制。

我一直在尝试让机器人发送嵌入的公共消息。

embed=discord.Embed(title="Tile", description="Desc", color=0x00ff00)
embed.add_field(name="Fiel1", value="hi", inline=False)
embed.add_field(name="Field2", value="hi2", inline=False)
await self.bot.say(embed=embed)

执行此代码时,我收到错误“Embed”不是模块“discord”的有效成员。所有网站都向我展示此代码,我不知道有任何其他方式来发送嵌入。


为了让它工作,我将你的 send_message 行更改为await message.channel.send(embed=embed)

这是一个完整的示例代码,展示了它是如何适应的:

@client.event
async def on_message(message):
    if message.content.startswith('!hello'):
        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(embed=embedVar)

我使用discord.py 文档来帮助找到这个。https://discordpy.readthedocs.io/en/latest/api.html#discord.TextChannel.send用于发送方法的布局。

https://discordpy.readthedocs.io/en/latest/api.html#embed对于嵌入类。

1.0版本之前:如果您使用的是1.0之前的版本,请使用以下方法await client.send_message(message.channel, embed=embed)反而。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何通过我的 Discord 机器人使用 /python 发送嵌入内容? 的相关文章