我试图使用消息ID创建一个命令来编辑bot消息,我做了一个前缀,它工作得很好,但是我不知道如何使斜杠命令变得更简单,下面是我尝试的:
@bot.slash_command(name="edit", description="Edits the bot messages", guild=discord.Object(id=824342611774144543))
async def edit(self, id: Option(int, description="Message ID", required=True), message: Option(str, description="New Input Message", required=True)):
msg = self.bot.get_message(id)
await msg.edit(message)当我尝试使用它时,斜杠命令没有显示任何选项。
发布于 2022-10-06 23:42:41
命令需要命令上下文的ctx参数。
Pycord在**guild_ids**参数中使用实际的公会ids,而不是在discord.py中为guild使用discord.Objects。
既然你有self参数,我就假设你在齿轮上。您将需要使用@discord.slash_command装饰器。
另外,bot.get_message检查缓存,这意味着它不会一直找到消息。相反,您应该使用await ctx.channel.fetch_message(id),它进行API调用,如果消息存在于当前通道中,则会找到它。
@discord.slash_command(name="edit", description="Edits the bot messages", guild_ids=[824342611774144543]) # use guild_ids instead
async def edit(
self,
ctx: discord.ApplicationContext, # missing ctx parameter
id: Option(int, description="Message ID", required=True),
message: Option(str, description="New Input Message", required=True)
):
msg = await ctx.channel.fetch_message(id) # fetch instead
await msg.edit(message)如果您还有其他关于pycord的问题,最好在支持服务器中询问。
https://stackoverflow.com/questions/73979173
复制相似问题