【问题标题】:Discord bot send embed message to another channelDiscord bot 将嵌入消息发送到另一个频道
【发布时间】:2018-11-24 14:43:09
【问题描述】:

我不知道如何将机器人上的嵌入消息从一个渠道发送到另一个渠道,尽管我可以弄清楚如何将自己的消息发送到另一个渠道:

@bot.command(pass_context=True)
async def tf1(ctx):
    embed=discord.Embed(title="Test", description="1", color=0x5bcdee)
    embed.set_footer(text="Test2")
    await bot.say(discord.Object(id='456277299189383168'),  embed=embed)

这个似乎不起作用,每当我发送它时,我都会收到这个<discord.object.Object object at 0x03B66BD0>,然后是嵌入的消息。

另一方面,当我尝试复制消息而不是嵌入消息时,这有效,这里是复制我的消息的代码:

@bot.command(pass_context=True)
async def obisowner(ctx, *, mesg):
    await bot.send_message(discord.Object(id='456277299189383168'), "{}".format(mesg))

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    你必须使用 discord.py 重写库

    首先,你需要创建命令:

    @bot.command()
    async def embed(ctx):
    

    之后,您需要设置消息发送到哪个频道:

    channel = bot.get_channel(channel id)
    

    现在,您需要创建嵌入:

    embed = discord.Embed(title="Embed test", description="A test for my discord bot", color=0x5bcdee)
    embed.add_field(name="Hello!", value="Hello World!", inline=False)
    

    最后,发送消息!

    await channel.send(embed=embed)
    

    完整的命令代码:

    @bot.command()
    async def embed(ctx):
        channel = bot.get_channel(channel id)
        embed = discord.Embed(title="Embed test", description="A test for my discord bot", color=0x5bcdee)
        embed.add_field(name="Hello!", value="Hello World!", inline=False)
        await channel.send(embed=embed)
    

    【讨论】:

      【解决方案2】:

      bot.say() 接受第一个位置参数message,并将消息发送并嵌入到命令上下文的通道(即机器人接收命令消息的通道)。

      由于您想将消息发送到不同的频道,请改用bot.send_message()

      await bot.send_message(discord.Object(id='456277299189383168'),  embed=embed)
      

      【讨论】:

        猜你喜欢
        • 2023-03-07
        • 2020-03-19
        • 2021-01-10
        • 2023-03-27
        • 1970-01-01
        • 2022-01-05
        • 2022-01-21
        • 1970-01-01
        • 2021-08-18
        相关资源
        最近更新 更多