ReferenceError:消息未定义

时间:2019-12-10 09:47:11

标签: discord

const Discord = require ('discord.js');
const bot = new Discord.Client();

const token = 'TOKEN';

bot.on('ready', () =>{
  console.log('Online');

  if(msg.includes('hi')) {
    message.delete();
    message.author.send('hello')
  }
})
bot.login(token);

1 个答案:

答案 0 :(得分:0)

您需要将代码放入.on()函数中。例如,收听消息:

const Discord = require ('discord.js');
const bot = new Discord.Client();

const token = 'TOKEN';

bot.on('ready', () =>{
  console.log('Online');
})

bot.on('message', (message) => {
  if(message.includes('hi')) {
    message.delete();
    message.author.send('hello')
  }
})

bot.login(token);

请注意,您不能使用msg message,必须选择一个变量名。