Discord JavaScript (node:1068) DeprecationWarning: 消息事件已弃用
Discord JavaScript (node:1068) DeprecationWarning: The message event is deprecated
所以当我 运行 命令时,我一直在尝试获取 n 个简单的 pong 消息,但是我得到了这个错误
代码:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '/stock';
client.once('ready', () => {
console.log('StockBot is online!');
});
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
} });
我屏蔽了登录码。
错误:
(node:1068) DeprecationWarning: The message event is deprecated. Use
messageCreate instead (Use node --trace-deprecation ...
to show
where the warning was created)
enter image description here
从 v13 开始,message
事件已被弃用。将您的代码替换为:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '/stock';
client.once('ready', () => {
console.log('StockBot is online!');
});
client.on('messageCreate', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
} });
所以当我 运行 命令时,我一直在尝试获取 n 个简单的 pong 消息,但是我得到了这个错误
代码:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '/stock';
client.once('ready', () => {
console.log('StockBot is online!');
});
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
} });
我屏蔽了登录码。
错误:
(node:1068) DeprecationWarning: The message event is deprecated. Use messageCreate instead (Use
node --trace-deprecation ...
to show where the warning was created)
enter image description here
从 v13 开始,message
事件已被弃用。将您的代码替换为:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '/stock';
client.once('ready', () => {
console.log('StockBot is online!');
});
client.on('messageCreate', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
} });