簡體   English   中英

如何在 discord.py 中使用表情符號按鈕編輯嵌入?

[英]How can I edit embed with emoji buttons in discord.py?

如何在 discord.py 中使用表情符號按鈕編輯嵌入? 我是這樣弄的。。但是不行。。

@client.event
async def on_message(message):
    if message.content.startswith("!menu"):
        embed=discord.Embed(color=0x00FFFF, title=f'Menu', description= f'🔴 - test1 \n🟠 - test2 \n🟡 - test3 \n🟢 - test4 \n🔵 - test5 \n🟣 - test6', timestamp=message.created_at)
        embed.set_footer(text=f'-', icon_url=message.author.avatar_url)
        msg = await message.channel.send(embed=embed)
        await msg.add_reaction('🔴')await msg.reaction_add('🟠')
        await msg.add_reaction('🟡')
        await msg.add_reaction('🟢')
        await msg.add_reaction('🔵')
        await msg.add_reaction('🟣')
if str(msg.add_reaction) == '🔴':
            embed1=discord.Embed(color=0x00FFFF, title=f'edit1', description= f'test1')
            await msg.edit(embed=embed1)

我想要一些編輯代碼!

歡迎來到 StackOverflow,您可以使用discord.ext.menus 這是您需要安裝它的方法。

pip install git+https://github.com/Rapptz/discord-ext-menus

然后你可以做這樣的事情。

import discord
from discord.ext import menus

class ColorMenu(menus.Menu):
    def __init__(self, embed):
        super().__init__(timeout=30.0, delete_message_after=True)
        self.embed = embed
        self.result = None

   async def send_initial_message(self, ctx, channel):
       return await channel.send(embed=self.embed)

   @menus.button('🔴')
   async def red_button(self, payload):
       # do what ever you want with this.
       # right now I'm going to just edit the message
       self.embed.description = 'test1'
       self.embed.title = 'title1'
       self.message.edit(embed=self.embed)

   # do the same thing for other reactions


然后創建一個新命令並實例化 class,如下所示:

@bot.command()
async def menu(ctx):
    color_menu = ColorMenu()
    color_menu.start(ctx)

你完成了。

祝你的機器人好運。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM