[英]Pycord - Edit bot messages using Slash Commands
我正在嘗試使用消息 ID 發出命令來編輯機器人消息,我做了一個前綴並且效果很好,但我不確定如何使斜杠命令變得更容易,這是我嘗試過的:
@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)
當我嘗試使用斜杠命令時,它沒有顯示任何選項
命令需要一個ctx
參數作為命令的上下文。
Pycord 在 ** guild_ids
** 參數中使用實際的公會 ID,而不是 discord.py 中的guild
discord.Object
s。
由於您有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的問題,最好在支持服務器中詢問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.