Nor*_* A. 3 python embed discord discord.py
我一直在使用新的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)
Run Code Online (Sandbox Code Playgroud)
执行此代码时,我收到"嵌入"不是模块"discord"的有效成员的错误.所有网站,给我看这个代码,我不知道任何其他方式发送嵌入.
为了让它工作,我将你的send_message行更改为
await message.channel.send(embed=embed)
这是一个完整的示例代码,以显示它是如何适合的:
@client.event
async def on_message(message):
if message.content.startswith('!hello'):
embed = discord.Embed(title="Title", description="Desc", color=0x00ff00)
embed.add_field(name="Field1", value="hi", inline=False)
embed.add_field(name="Field2", value="hi2", inline=False)
await message.channel.send(embed=embed)
Run Code Online (Sandbox Code Playgroud)
我使用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详细信息
执行此代码时,出现“嵌入”不是模块“discord”的有效成员的错误。所有网站,给我看这个代码,我不知道有什么其他的方式来发送嵌入。
这意味着你已经过时了。使用pip更新您的库的版本。
pip install --upgrade discord.py
Run Code Online (Sandbox Code Playgroud)