[英]discord py command not found
我正在制作一个 discord 机器人,并尝试使用 / 菜单上下文命令。 这是我的代码:
import discord
from discord.ext import commands
from dotenv import load_dotenv
import requests
load_dotenv()
url = "https://discord.com/api/v10/applications/ID/commands"
TOKEN = "TOKEN"
# This is an example CHAT_INPUT or Slash Command, with a type of 1
json = {
"name": "ping",
"type": 1,
"description": "test lmao",
"options": [
{
"name": "test",
"description": "test",
"type": 3,
"required": True,
}
]
}
# For authorization, you can use either your bot token
headers = {
"Authorization": "Bot TOKEN"
}
r = requests.post(url, headers=headers, json=json)
bot = commands.Bot(command_prefix='/',intents=discord.Intents.all())
@bot.event
async def on_read():
print("Bot is ready!")
@bot.command(pass_context = True)
async def ping(ctx, arg):
await ctx.send("Pong! "+ str(arg))
bot.run(TOKEN)
应用程序命令出现,但机器人没有响应,我收到此错误:discord.app_commands.errors.CommandNotFound:找不到应用程序命令“ping”
似乎您尝试使用斜杠命令,但您没有定义任何应用程序命令(斜杠命令),而是定义了文本命令。
对于斜线命令,您应该使用 discord.py 的 app_commands package。它还负责在 discord 注册应用程序命令
https://discordpy.readthedocs.io/en/stable/interactions/api.html#application-commands
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.