問題描述
我一直在開發(fā)一個新的 Discord 機器人.
I've been working a new Discord bot.
我學(xué)到了一些東西,現(xiàn)在,我想讓這些東西變得更加定制化.
I've learnt a few stuff,and, now, I'd like to make the things a little more custom.
我一直在嘗試讓機器人發(fā)送嵌入消息,而不是普通消息.
I've been trying to make the bot send embeds, instead, of a common message.
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)
執(zhí)行此代碼時,我收到嵌入"不是模塊不和諧"模塊的有效成員的錯誤.所有網(wǎng)站,給我看這段代碼,我不知道有什么其他的方式來發(fā)送嵌入.
When executing this code, I get the error that 'Embed' is not a valid member of the module 'discord'. All websites, show me this code, and I have no idea of any other way to send a embed.
推薦答案
為了讓它工作,我將你的 send_message 行改為等待 message.channel.send(embed=embed)
To get it to work I changed your send_message line to
await message.channel.send(embed=embed)
這是一個完整的示例代碼,展示了它是如何適應(yīng)的:
Here is a full example bit of code to show how it all fits:
@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 用于發(fā)送方法的布局.
I used the discord.py docs to help find this. https://discordpy.readthedocs.io/en/latest/api.html#discord.TextChannel.send for the layout of the send method.
https://discordpy.readthedocs.io/en/latest/api.html#embed 用于 Embed 類.
https://discordpy.readthedocs.io/en/latest/api.html#embed for the Embed class.
1.0 之前的版本:如果您使用的是 1.0 之前的版本,請改用 await client.send_message(message.channel, embed=embed)
方法.
Before version 1.0: If you're using a version before 1.0, use the method await client.send_message(message.channel, embed=embed)
instead.
這篇關(guān)于如何通過我的 Discord 機器人發(fā)送嵌入,使用 python?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!