javascript - Discord Bot 没有响应
问题描述
出于某种原因,基本ping pong
命令不起作用。我从网站上复制并粘贴了它,但我不确定它有什么问题。
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.login('hidden')
client.once('ready', () => {
console.log('Ready!');
});
client.on('interactionCreate', interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'ping') {
interaction.reply('Pong.');
}
});
没有日志错误使它更奇怪。我知道它正在连接,因为当我node index.js
在 cmd 面板中执行操作时,机器人会在线显示。
解决方案
首先,我建议您在开头修复缩进并将client.login
调用移至结尾,因为discord.js
文档就是这样做的。
此外,您确定您使用的是 Discord.js v13 吗?这些事件是在 v13 中添加的,因此如果您使用 Discord.js v12 运行它,您的机器人将运行,但您的函数将永远不会被调用。
否则,您的代码看起来不错(对我来说),但我不是专家。
推荐阅读
- javascript - 成功 import-jdl 后,JHipster 实体菜单为空
- python - 使用 matplotlib 或 seaborn 的多列线图
- c# - 如何触发按钮 C#
- ldap - 将 Opendj 从 2.6.4 升级到 3.5.3 以用于复制服务器
- python - 在模板中使用 for 循环显示多个动态对象
- angular - 使用 data-toggle 和 data-target 仅折叠通过 Angular 中的 Ng-For 部署的一组项目中的一项
- python - 如何将座位标记为每部电影已占用?
- python - 如何将整数大小和指针声明从 C++ 转换为 Python?
- redirect - CNAME 也会重定向子文件夹吗?
- git - 为什么 powershell env 可以在本地工作,但不能与 dockerfile 一起工作?