首页 文章

如何通过我的Discord bot发送嵌入,用/ python?

提问于
浏览
2

我一直在使用新的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)

执行此代码时,我收到“嵌入”不是模块“discord”的有效成员的错误 . 所有网站,给我看这个代码,我不知道任何其他方式发送嵌入 .

2 回答

  • 4

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

    这是一个完整的示例代码,以显示它是如何适合的:

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

    我使用discord.py文档来帮助找到它 . http://discordpy.readthedocs.io/en/latest/api.html#discord.Client.send_message用于send_message的布局

    http://discordpy.readthedocs.io/en/latest/api.html#embed获取API详细信息

  • 7

    执行此代码时,我收到“嵌入”不是模块“discord”的有效成员的错误 . 所有网站,给我看这个代码,我不知道任何其他方式发送嵌入 .

    这意味着你已经过时了 . 使用 pip 更新您的库版本 .

    pip install --upgrade discord.py
    

相关问题