【发布时间】:2021-02-01 02:42:09
【问题描述】:
所以当我使用 node.js 启动我自己的 Discord Bot 时,我正在尝试编写它。确实可以,但是当我输入 *ping 时,它没有应有的响应
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '*';
client.once('ready', () => {
console.log('Testbot is online!');
});
client.on('message', message => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.lenght).split(" ");
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
}
});
哪里出错了?
【问题讨论】:
-
如果您尝试记录
args和command,您会得到什么? -
console.log(args)在const args下,与command(console.log(command)) 相同。检查控制台中的输出 -
你也可以尝试登录
message -
您将
length拼错为lenght。 -
const args...这行有错字:prefix.lenght应该是prefix.length
标签: javascript discord.js