Discord Bot' InteractionCreate'听众响应了几次,然后退出响应而无需我更改代码
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
注意:
我正在使用这些意图:
flags.guilds,flags.guild_messages,flags.guild_emojis_and_and_stickers
我正在使用.mjs文件作为命令,
import()注册它们。当我离开时,那是与这些东西的工作状态。我还尝试恢复
需要
,因为文档使用它,但没有更改任何内容。我曾经曾经得到此处描述的错误我现在看到
在部署命令时成功注册的应用程序命令
。更新:
需要
用于导入文件和注册事件和命令的语法似乎有效。 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 ofinteractionCreate
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 torequire
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论