最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Discord.js消息未定义

IT培训 admin 10浏览 0评论

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");

希望能帮助到你。

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");

希望能帮助到你。

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论