discord.py在特定通道中嵌入反应

2024-05-23 16:05:51 发布

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

我想做一个建议命令。命令正在运行。该命令向名为“建议”的特定通道发送嵌入。我想给嵌入添加反应(❌ 和✅). 现在我需要你的帮助。我无法向嵌入添加反应。这是我的实际代码,没有添加反应:

@bot.command()
async def suggestion(ctx, *, content: str):
    title, description= content.split('/')
    embed = discord.Embed(title=title, description=description, color=0x00ff40)
    channel = bot.get_channel(857413508224385054)
    await channel.send(embed=embed)
    await ctx.send("your suggestion is send!")
    await ctx.message.delete()

Tags: 代码命令sendasynctitlebotchannelembed
1条回答
网友
1楼 · 发布于 2024-05-23 16:05:51

您需要定义嵌入以添加反应

简单地做:

@bot.command()
async def suggestion(ctx, *, content: str):
    title, description= content.split('/')
    embed = discord.Embed(title=title, description=description, color=0x00ff40)
    channel = bot.get_channel(857413508224385054)
    test = await channel.send(embed=embed) # Define the message
    await test.add_reaction("✅") # Add reactions
    await test.add_reaction("❌")
    await ctx.send("your suggestion is send!")
    await ctx.message.delete()

另一种方法是设置一个事件来侦听频道中的消息:

@bot.event
async def on_message(message):
    if message.channel.id == 857413508224385054: # Checks if the channel is correct
        await message.add_reaction("✅") # Adds the reaction to all new messages
        await message.add_reaction("❌")

相关问题 更多 >