首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nextcord命令

Nextcord命令
EN

Stack Overflow用户
提问于 2022-01-16 16:45:18
回答 3查看 4K关注 0票数 2

我听说nextcord现在有斜杠命令了!太好了,这就是为什么我想把它们加到我的机器人里。我已经看过YouTube教程了,但由于某种原因,它不起作用。这是我的main.py文件

代码语言:javascript
复制
from IMPORTANT.keep_alive import keep_alive
import os

try:
    from nextcord.ext import commands
    from nextcord import Interaction
    import nextcord
    
except ImportError:
    os.system("pip install -U nextcord")
    from nextcord.ext import commands
    from nextcord import Interaction
    import nextcord

intents = nextcord.Intents().all()
bot = commands.Bot(command_prefix="+", intents=intents)
bot.remove_command("help")
server = 896366068417830933

for file in os.listdir("./cogs/commands"):
    if file.endswith(".py"): 
        name = file[:-3]
        bot.load_extension(f"cogs.commands.{name}") 

for file in os.listdir("./cogs/events"):
    if file.endswith(".py"): 
        name = file[:-3]
        bot.load_extension(f"cogs.events.{name}") 
    
# slash command test
@bot.slash_command(name="test", description="commande de test", guild_ids=[server])
async def test(interaction: Interaction):
    await interaction.response.send_message("les slashs commands fonctionnent")

keep_alive()
bot.run(os.getenv("TOKEN"))

编辑: Idk如果它改变了什么,但我使用repl.it

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2022-01-16 17:23:20

我试过你的代码,它对我有用。也许这个能治好它

如果您使用的是事件“

  1. ”,则为on_interaction

如果self.client.process_application_commands(interaction) interaction.type == InteractionType.application_command:等待

  1. 使用以下权限重新邀请机器人

applications.commands

票数 1
EN

Stack Overflow用户

发布于 2022-01-23 15:43:01

问题可能在于,通过查看您的代码,您使命令名为"commande de test"和斜杠命令不会那样工作,除非您使用所谓的子命令,所以我认为只需调用命令test或其他什么。

票数 1
EN

Stack Overflow用户

发布于 2022-01-23 17:46:12

  1. 你只说“不工作”-这是一个非常广泛的问题。
  2. 已经授权您的机器人与OAuth2 applications.commands (邀请链接,这就像bot范围)。任何用户都需要重新使用--不需要踢机器人,只需要重用链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70732110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档