【问题标题】:How can I edit embed with emoji buttons in discord.py?如何在 discord.py 中使用表情符号按钮编辑嵌入?
【发布时间】:2021-03-21 04:05:35
【问题描述】:

如何在 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)

我想要一些编辑代码!!

【问题讨论】:

  • 为此使用discord.ext.menus,你可以用经典的方式做到这一点,但这很痛苦。

标签: python discord discord.py edit


【解决方案1】:

欢迎使用 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


然后创建一个新命令并实例化该类,如下所示:

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

你已经完成了。

祝你的机器人好运。

【讨论】:

    猜你喜欢
    • 2020-07-31
    • 2023-01-26
    • 2021-11-29
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2022-11-16
    • 2021-11-23
    相关资源
    最近更新 更多