无法在Discord.py中发送嵌入

2024-09-30 20:24:31 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的代码:

@client.event async def on_message(message): if message.content.startswith('.announce'): first_embed = discord.Embed(title="Enter announcement", color=0x2bff00) msgg = await message.channel.send(embed=first_embed) def check(m): return m.channel == message.channel msg = await client.wait_for('message', check=check) ann = msg.content print(ann) time.sleep(10) new_embed = discord.Embed(title='Enter Colour(Red, Green, Yellow)', color=0x2bff00) await msgg.edit(embed=new_embed) def check(m): return m.channel == message.channel msg = await client.wait_for('message', check=check) colo = msg.content print(colo) channel = client.get_channel(733344357884756018) if(colo=='Red'): coloo = discord.Colour(0xFF0000) if(colo == 'Green'): coloo = discord.Colour(0x2bff00) if(colo == 'Yellow'): coloo = discord.Colour(0xFFFF00) await channel.send(discord.Embed(title=ann, color=coloo)) client.run('TOKEN')

不幸的是,当我运行程序时,它会正确地获取输入和所有内容,但输出结果是:

<discord.embeds.Embed object at 0x05B3FBF8>

我正在努力实现的目标:

To basically Send embed Announcements in my server cus it looks fancy lol.

如有任何帮助或改进我的代码,我们将不胜感激:)

图像:

My Input in Discord

Output


Tags: clientmessageifdefcheckchannelmsgembed
1条回答
网友
1楼 · 发布于 2024-09-30 20:24:31

您需要使用.send(embed=discord.Embed)指定您正在发送嵌入 以下是更新后的代码-

@client.event
async def on_message(message):
    if message.content.startswith('.announce'):
        first_embed = discord.Embed(title="Enter announcement", color=0x2bff00)
        msgg = await message.channel.send(embed=first_embed)
        def check(m):
            return m.channel == message.channel
          
        msg = await client.wait_for('message', check=check)
        ann = msg.content
        print(ann)
        time.sleep(10)
        new_embed = discord.Embed(title='Enter Colour(Red, Green, Yellow)', color=0x2bff00)         
  

        await msgg.edit(embed=new_embed)
        def check(m):
            return m.channel == message.channel
          
        msg = await client.wait_for('message', check=check)
        colo = msg.content
        print(colo)


        channel = client.get_channel(733344357884756018)
        if(colo=='Red'):
            coloo = discord.Colour(0xFF0000)
        if(colo == 'Green'):
            coloo = discord.Colour(0x2bff00)
        if(colo == 'Yellow'):
            coloo = discord.Colour(0xFFFF00)

        await channel.send(embed=discord.Embed(title=ann, color=coloo))


client.run('TOKEN')

相关问题 更多 >