响应来自不和谐的消息时,如何让我的机器人发送嵌入

时间:2020-12-30 14:28:08

标签: python python-3.x discord discord.py embed

我对机器人进行编程的方式我不确定如何使消息通过来自不和谐的消息嵌入发送。我可以让它发送正常的消息,但嵌入不会工作,我知道我做错了什么。我有点新所以!

@szn.event
async def on_message(message):

    if message.content == 'info':
        general_channel = szn.get_channel()

        myEmbed = discord.Embed(tiitle="test", description="", color="")
        myEmbed.add_field()
        myEmbed.set_footer()

        await general_channel.send(embed=myEmbed)

这是我的代码

2 个答案:

答案 0 :(得分:0)

注意事项:

  1. get_channel() 需要一个 ID 作为参数
  2. add_field() 需要名称和值
  3. set_footer() 至少需要文本

修改后的代码:

# CHANNEL_ID is the id of the channel you want to send message to
@szn.event
async def on_message(message):

    if message.content == 'info':
        general_channel = szn.get_channel(CHANNEL_ID)

        myEmbed = discord.Embed(title="test")
        myEmbed.add_field(name="Field 1", value="Value 1")
        myEmbed.set_footer(text="Footer")

        await general_channel.send(embed=myEmbed)

答案 1 :(得分:0)

需要注意的是,如果您正在获取发送消息的频道,则可以执行 'message.channel'

async def on_message(message):
    if message.content == 'info':
        myEmbed.title = "[insert the title of the embed]"
        myEmbed.description = '[insert the description of the embed]'
        myEmbed.color = 0xfc0303 [hex color, you can search up hex colors and then put '0x' in front of it] #this is optional
        myEmbed.set_footer(text = "[text]") #also optional
        myEmbed.set_image(url = "[image URL]") #again, optional
        await message.channel.send(embed=myEmbed)

可能还有更多我不知道的嵌入内容,但这些应该很容易查找