簡體   English   中英

消息編輯 Pycord

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM