ReferenceError: message is not defined, how to solve?
ReferenceError: message is not defined, how to solve?
我正在 discord.js 上学习编码,所以我可能有一些错误,如果您发现任何问题,请随时纠正我。现在这是我面临的错误:ReferenceError: message is not defined
代码如下:
const Discord = require('discord.js');
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES
]
});
const prefix = '!';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for (const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('This bot is online!');
});
client.on('message', message =>{
if (!message.content.startsWith(prefix) || message.author.client) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping'){
message.channel.send('pong!');
} else if (command == 'joe'){
message.channel.send('mama ;)');
} else if (command == 'deez'){
message.channel.send('NUTS!!');
} else if (command == 'ur'){
message.channel.send('mama');
} else if (command === 'kick'){
client.commands.get('kick').execute(message, args);
} else if (command === 'ban'){
client.commands.get('ban').execute(message, args);
}
});
client.login('token')
当我 运行 你的代码时,一切都对我有用。您收到错误的原因可能是消息在 Discord v13 中已被弃用,如此处 Updating from v12 to v13 所示。但这不会引发错误,只会显示 (node:30426) DeprecationWarning: The message event is deprecated. Use messageCreate instead
将 client.on('message')
中的活动更改为 client.on('messageCreate')
并查看是否有效。如果你能post这里的整个错误信息
,那将会更有帮助
我正在 discord.js 上学习编码,所以我可能有一些错误,如果您发现任何问题,请随时纠正我。现在这是我面临的错误:ReferenceError: message is not defined
代码如下:
const Discord = require('discord.js');
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES
]
});
const prefix = '!';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for (const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('This bot is online!');
});
client.on('message', message =>{
if (!message.content.startsWith(prefix) || message.author.client) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping'){
message.channel.send('pong!');
} else if (command == 'joe'){
message.channel.send('mama ;)');
} else if (command == 'deez'){
message.channel.send('NUTS!!');
} else if (command == 'ur'){
message.channel.send('mama');
} else if (command === 'kick'){
client.commands.get('kick').execute(message, args);
} else if (command === 'ban'){
client.commands.get('ban').execute(message, args);
}
});
client.login('token')
当我 运行 你的代码时,一切都对我有用。您收到错误的原因可能是消息在 Discord v13 中已被弃用,如此处 Updating from v12 to v13 所示。但这不会引发错误,只会显示 (node:30426) DeprecationWarning: The message event is deprecated. Use messageCreate instead
将 client.on('message')
中的活动更改为 client.on('messageCreate')
并查看是否有效。如果你能post这里的整个错误信息