最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Discord.js消息未定义

运维笔记admin8浏览0评论

Discord.js消息未定义

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. 暂无评论