【发布时间】:2021-12-16 13:59:15
【问题描述】:
由于某种原因,基本的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.');
}
});
没有日志错误使它更奇怪。我知道它正在连接,因为当我在 cmd 面板中执行 node index.js 时,机器人会在线显示。
【问题讨论】:
-
您的控制台是否显示“Ready!”?
-
您的交互是否到达了它的事件处理程序?
-
是的,它显示已准备就绪。当我输入 !ping 时,它没有任何奇怪的响应。
标签: javascript node.js discord bots