我已经有 3 个完美运行的 app_commands,当您在不和谐聊天中输入“/”时也会显示这些命令。但是,当我尝试制作第四个时,即使是一个简单的只是为了测试,现在算一下我同步了多少,它并没有出现在命令列表中。是的,我不仅像白痴一样搜索“最近使用的命令”。
这是我的第四个命令(没有显示):
这是一条简单的消息,没什么花哨的。
@app_commands.command(name="tell_me_a_joke",description="tells you a *joke* ;)")
async def joke(self,ctx:discord.Interaction):
await ctx.response.send_message("https://u.gg/lol/profile/euw1/thebausffs-euw/overview")
这是 3 个工作命令之一:
@app_commands.command(name="roll_a_dice", description="like the name states, this command roles a dice.")
async def dice(self,ctx: discord.Interaction):
zahl = rs.randint(1,6)
messagelist = [f"The dice shows **{str(zahl)}** eyes.",f"A **{str(zahl)}** was rolled", f"You threw a **{str(zahl)}**"]
await ctx.response.send_message(rs.choice(messagelist))
我什至尝试将机器人从服务器中踢出并重新邀请他,因为这解决了过去的一些问题。我在公会和全球范围内进行了本地同步。问题是什么?我是否需要等待更长的时间,因为不和谐的服务器很慢?
应用程序命令每天创建 200 个命令的限制。 来源因为应用程序命令是全局的,不和谐希望您创建它们一次。正如西尔维奥在这里所说:Silvios 答案
这就是创建命令。您只需创建每个命令一次,而不是每次机器人运行一次。 Discord 将命令与您的机器人的唯一 ID 相关联。
他还提到了如何解决它,我建议阅读原始答案。
但是 对于简单的机器人和简单的操作,通常不建议使用应用程序命令。使用 bot.commands 没有限制,而且对初学者非常友好。以下是如何与 bot.command 配合使用的代码片段:
import discord
from discord.ext import commands
intents = discord.Intents.all() #Can be changed for more specific intents.
bot = commands.Bot(intents=intents,command_prefix="!!") #You can use any prefix other than slash.
#Slash commands are created differently.
@bot.event
async def on_ready(): #It's good practice to have on_ready function
print(f"Logged in as {bot.user.name}") #Successfully loaded the bot
@bot.command(help="Tells you a *joke* ;)") #when [yourprefix]help [thiscommandsname] used it will show this description
async def joke(ctx):
await ctx.send("https://u.gg/lol/profile/euw1/thebausffs-euw/overview")
bot.run("YourBotToken")
此方法的缺点是您无法像在 app_commands 中那样输入命令时获得反馈。但您仍然可以使用带有前缀的帮助命令。