![](/img/trans.png)
[英]How can I edit an embed color with my discord bot with 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.