[英]How to edit a buttons style when it's clicked. (Pycord) using edit_message()
[英]Message Edit Pycord
我正在尝试编辑建议以接受建议,我想使用消息 ID 编辑嵌入标题,消息 ID 存储在我的数据库中,用户将左键单击建议以获取 ID,然后运行此命令接受它 /suggestaccept (MessageID) (NewEmbedTitle) 但它返回
Traceback(最近一次调用):文件“C:\Users\jackd\Documents\Felbcord Py.venv\lib\site-packages\discord\bot.py”,第 993 行,invoke_application_command await ctx.command.invoke(ctx ) 文件“C:\Users\jackd\Documents\Felbcord Py.venv\lib\site-packages\discord\commands\core.py”,第 357 行,在调用中
等待注入(ctx)文件“C:\Users\jackd\Documents\Felbcord Py.venv\lib\site-packages\discord\commands\core.py”,第 134 行,已包装
从 exc discord.errors.ApplicationCommandInvokeError 引发 ApplicationCommandInvokeError(exc):应用程序命令引发异常:AttributeError:“NoneType”对象没有属性“编辑”
import discord
from pymongo import MongoClient
from discord.ext.commands import slash_command
from discord.ext import commands
from discord.ext.commands import Cog
class Suggestions(discord.ui.Modal):
def __init__(self,bot,*args, **kwargs) -> None:
self.bot = bot
super().__init__(*args, **kwargs)
self.add_item(discord.ui.InputText(label="Your Suggestion: ", style=discord.InputTextStyle.long))
async def callback(self, interaction: discord.Interaction):
m = await interaction.response.send_message("Suggestion send!", ephemeral=True)
suggest = discord.Embed(title=f"Suggestion by {interaction.user} Under Review ",color=discord.Color.blue())
suggest.add_field(name="Your Suggestion: ", value=self.children[0].value)
suggest.set_footer(text=f"Message id: {m.id} ")
channel = self.bot.get_channel(987396375069224960)
embed = await channel.send(embed=suggest)
await embed.add_reaction('☑')
await embed.add_reaction('❌')
db = self.bot.mongoConnect["FelBot"]
collection = db["FelBot"]
await collection.find_one({'_id' : m.id})
await collection.insert_one( {'_id': m.id})
class Suggest(commands.Cog):
def __init__(self,bot):
self.bot = bot
@slash_command(name="suggest", description="suggestions")
@commands.cooldown(1,7200, commands.BucketType.user)
async def modal_slash(self,ctx: discord.ApplicationContext):
await ctx.send_modal(Suggestions(self.bot, title="Suggestion"))
@slash_command(name="suggestaccept",description="Accept a suggestion")
async def suggestaccept(self,ctx, m_id: discord.Option(str, description="Message id."),new_embed:discord.Option(str, description="New embed")):
m = self.bot.get_message(m_id)
await m.edit(new_embed=new_embed)
await ctx.respond('Accepted suggestion by {interaction.user}')
def setup(bot):
bot.add_cog(Suggest(bot))```
您将m_id
设置为 str。 将其转换为 int。 此外,在编辑消息时,它需要embed=new_embed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.