我试图编辑一个建议来接受一个建议,我想用消息ID编辑一个嵌入的标题,消息id存储在我的db中,用户将左击这个建议来获得ID,然后运行这个命令来接受它-- /suggestaccept (MessageID) (NewEmbedTitle),但是它会返回。
回溯(最近一次调用):文件“C:\Users\jackd\Documents\FelbcordPy.venv\lib\site-packages\discordbot.py”,第993行,在invoke_application_command await ctx.command.invoke(ctx)文件“C:\Users\jackd\Documents\Felbcord357中”,在invoke中
等待注入(Ctx)文件“C:\Users\jackd\Documents\Felbcord134号,包装
从exc引发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))```发布于 2022-06-25 17:47:29
您将m_id设置为str。将其转换为int。另外,在编辑消息时,它需要是embed=new_embed
https://stackoverflow.com/questions/72753466
复制相似问题