How can I edit embed with emoji buttons in discord.py? I was making it like this.. but it doesn't works..
@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)
I want some edit codes!!
Welcome to StackOverflow, you can use discord.ext.menus
. Here's how you need to install it.
pip install git+https://github.com/Rapptz/discord-ext-menus
.
Then you can do something like this.
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
Then make a new command and instantiate the class, like this:
@bot.command()
async def menu(ctx):
color_menu = ColorMenu()
color_menu.start(ctx)
And you're done.
Good luck with your bot.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.