Discord Bot' InteractionCreate'听众响应了几次,然后退出响应而无需我更改代码

发布于 2025-02-01 12:56:19 字数 2065 浏览 3 评论 0原文

OS Windows 11

版本:

  • node.js:v16.13.0
  • npm:8.1.0
  • discord.js:^13.7.0

软件包:

  • “@discordjs/builders”:“^0.13.0”,
  • “@discordjs/reast”: 0.4.1“,
  • “ discord-api types”:“^0.32.1”

范围:

  • applications.commands
  • bot bot

bot bot许可:

  • 管理员

我关注教程来自Discord docs ,并为我的机器人构建slash命令。我能够注册命令并获取成功消息,然后 /ping bot并获得响应。我承诺走开了。几个小时后,我回来开始构建更多命令,并且机器人不再响应 /ping。实际上,根本没有达到这个代码块:

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;
    const command = client.commands.get(interaction.commandName);
    if (!command) return;
    try {
        await command.execute(interaction);
    } catch (error) {
        console.error(error);
        await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
    }
});

我已经尝试过:

  • 重新安装NPM
  • Replastall Discord.js
  • 踢机器人并重做示波器和权限(不更改)
  • 等待几个小时,请访问API以赶上注册注册slash命令
  • 已尝试互动而不是互动create

注意:

  • 需要用于导入文件和注册事件和命令的语法似乎有效。 ES6模块似乎没有让我注册命令。

OS Windows 11

Versions:

  • Node.js : v16.13.0
  • npm : 8.1.0
  • discord.js : ^13.7.0

Packages:

  • "@discordjs/builders": "^0.13.0",
  • "@discordjs/rest": "^0.4.1",
  • "discord-api-types": "^0.32.1"

Scopes:

  • applications.commands
  • bot

Bot permission:

  • administrator

I was following the tutorial from the discord docs and building slash commands for my bot. I was able to register the commands and get the success message, then /ping the bot and get a response. I committed and walked away. A few hours later I come back to start building more commands and the bot doesn't respond to /ping anymore. In fact, this block of code is not being reached at all:

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;
    const command = client.commands.get(interaction.commandName);
    if (!command) return;
    try {
        await command.execute(interaction);
    } catch (error) {
        console.error(error);
        await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
    }
});

I've tried:

  • reinstall npm
  • reinstall discord.js
  • kick the bot and redo the scopes and permissions (not changing them)
  • wait a few hours for the api to catch up registering the slash commands
  • tried interaction instead of interactionCreate

Notes:

  • I am using these intents : FLAGS.GUILDS, FLAGS.GUILD_MESSAGES, FLAGS.GUILD_EMOJIS_AND_STICKERS

  • I am using .mjs files for the commands, and import() syntax to register them. It was in a working state with those things when I left it. I've also tried reverting to require since the docs use that but that did not change anything.

  • I did once get the error described here but it went away and I now see Successfully registered application commands when I deploy the commands.

  • UPDATE:

  • The require syntax for importing files and registering events and commands seems to work. ES6 modules do not seem to let me register commands.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文