简体   繁体   English

消息编辑 Pycord

[英]Message Edit Pycord

I am trying to edit a suggestion to accept a suggestion, I want to edit a embeds title using the message ID, The messsage ID is stored in my db and the user would go left click the suggestion to get the id and then would run this command to accept it /suggestaccept (MessageID) (NewEmbedTitle) But it returns我正在尝试编辑建议以接受建议,我想使用消息 ID 编辑嵌入标题,消息 ID 存储在我的数据库中,用户将左键单击建议以获取 ID,然后运行此命令接受它 /suggestaccept (MessageID) (NewEmbedTitle) 但它返回

Traceback (most recent call last): File "C:\Users\jackd\Documents\Felbcord Py.venv\lib\site-packages\discord\bot.py", line 993, in invoke_application_command await ctx.command.invoke(ctx) File "C:\Users\jackd\Documents\Felbcord Py.venv\lib\site-packages\discord\commands\core.py", line 357, in invoke 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 行,在调用中
await injected(ctx) File "C:\Users\jackd\Documents\Felbcord Py.venv\lib\site-packages\discord\commands\core.py", line 134, in wrapped等待注入(ctx)文件“C:\Users\jackd\Documents\Felbcord Py.venv\lib\site-packages\discord\commands\core.py”,第 134 行,已包装
raise ApplicationCommandInvokeError(exc) from exc discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'NoneType' object has no attribute 'edit'从 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))```

You set m_id as a str.您将m_id设置为 str。 Convert it to an int.将其转换为 int。 Also when editting the message it needs to be embed=new_embed此外,在编辑消息时,它需要embed=new_embed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM