Discord.js消息未定义
const Discord = require('discord.js');
const testBot = new Discord.Client();
const config = require("./config.json");
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
testBot.on("message", (message) => {
if(command === 'help') {
message.channel.send('ok');
} else
if (command === 'hey') {
message.channel.send('yes?');
}
});
testBot.on('ready', () => {
console.log('I am ready!');
})
testBot.login("Secret");
我是node.js的初学者。
错误就是这个。 'ReferenceError:消息未定义'我该如何解决?
谢谢。
回答如下:我认为这是因为您的变量消息尚未声明
你可以试试这样的东西吗?
const Discord = require('discord.js');
const testBot = new Discord.Client();
const config = require("./config.json");
testBot.on("message", (message) => {
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if(command === 'help') {
message.channel.send('ok');
} else
if (command === 'hey') {
message.channel.send('yes?');
}
});
testBot.on('ready', () => {
console.log('I am ready!');
})
testBot.login("Secret");
希望能帮助到你。