Jack Douglas
Jack Douglas

Reputation: 1

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

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
await injected(ctx) File "C:\Users\jackd\Documents\Felbcord Py.venv\lib\site-packages\discord\commands\core.py", line 134, in wrapped
raise ApplicationCommandInvokeError(exc) from exc discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'NoneType' object has no attribute 'edit'

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))```

Upvotes: 0

Views: 1158

Answers (1)

Jason Martin
Jason Martin

Reputation: 736

You set m_id as a str. Convert it to an int. Also when editting the message it needs to be embed=new_embed

Upvotes: 0

Related Questions