【问题标题】:Discord.js ReferenceError: message is not definedDiscord.js ReferenceError:未定义消息
【发布时间】:2021-06-03 19:58:21
【问题描述】:

我正在尝试发出命令以清除我的不和谐中的消息,但我收到错误消息未定义。在终端内部的错误上方,我的return 下方有一个特定部分,第一行是它,有一个箭头指向它。

这是我的主要部分代码

const Discord = require('discord.js');
const client = new Discord.Client();
 
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('Codelyon 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') {
        client.commands.get('ping').execute(message, args);
    } 
    else if(command == 'ouryoutube') {
            client.commands.get('youtube').execute(message, args);
    } 
    else if(command == 'clear') {
            client.commands.get('clear').execute(message, args);
    }
});

这是我的命令代码

module.exports = {
    name: 'clear',
    description: "Clear Messages",
    execute(messages, args) {
        if(!args[0]) return message.reply("You must enter the number of messages you want to clear");
        if(isNaN(args[0])) return message.reply("Please Enter a Real Number.");
        
        if(args[0] > 100) return message.reply("You can't delete more then 100 messages");
        if(args[0] < 1) return message.reply("You must delete at least one message");
    }
}

感谢您的任何帮助! :)

【问题讨论】:

    标签: node.js visual-studio-code discord.js


    【解决方案1】:

    execute(messages, args) {...} 中有错字。第一个参数应该是message

    execute(message, args) {
      // code
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-01
      • 2020-02-22
      • 2020-06-27
      • 2021-06-20
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      相关资源
      最近更新 更多