【问题标题】:How do i make my bot send embeds when responding to messages from discord我如何让我的机器人在响应来自不和谐的消息时发送嵌入
【发布时间】:2021-04-07 01:14:19
【问题描述】:

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

@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)

这是我的代码

【问题讨论】:

  • szn 是什么?错误是什么?
  • 这个stackoverflow.com/questions/44862112/… 能回答你的问题吗?
  • 没有错误,嵌入只是不会发送,我也试过那个链接
  • szn 是我的客户只用一个名字运行的东西
  • 您是否将 ID 传递给 get_channel 或者您只是没有将其放入问题中?

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


【解决方案1】:

注意事项:

  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)

【讨论】:

  • 当我在所选频道中输入信息时仍然没有任何内容,我也尝试过使用我的前缀。 0 交互或登录终端
【解决方案2】:

需要注意的是,如果您正在获取发送消息的频道,您可以执行“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)

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

【讨论】:

    猜你喜欢
    • 2020-12-26
    • 2019-07-11
    • 2021-04-30
    • 2020-12-06
    • 2021-01-19
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多