我正在编写一个不和谐的机器人,但我向它添加了音乐命令,现在 clear 命令不起作用。
index.js:
const Discord = require('discord.js');
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION"]});
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('This bot is online!');
});
client.on('guildMemberAdd', guildMember =>{
let welcomeRole = guildMember.guild.roles.cache.find(role => role.name === 'member');
guildMember.roles.add(welcomeRole);
guildMember.guild.channels.cache.get('641315807745277993').send(`Welcome <@${guildMember.user.id}> to our server! Make sure to check out the <#791405102396735528> text channel!`)
});
client.on('message', message =>{
message.member.roles.cache.has
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 == 'youtube'){
client.commands.get('youtube').execute(message, args, Discord);
} else if (command == 'command'){
client.commands.get('command').execute(message, args, Discord);
} else if (command == 'clear'){
client.commands.get('clear').execute(message, args);
} else if (command == 'kick'){
client.commands.get('kick').execute(message, args);
} else if (command == 'ban'){
client.commands.get('ban').execute(message, args);
} else if (command =='mute'){
client.commands.get('mute').execute(message, args);
} else if (command =='unmute'){
client.commands.get('unmute').execute(message, args);
} else if (command =='reactionrole'){
client.commands.get('reactionrole').execute(message, args, Discord, client);
} else if (command =='play'){
client.commands.get('play').execute(message, args, Discord, client);
} else if (command =='leave'){
client.commands.get('leave').execute(message, args, Discord, client);
}
});
client.login('[BOT_TOKEN]');
clear.js:
module.exports = {
name: 'clear',
description: 'Clear messages!',
async execute(message, args){
if(!args[0]) return message.reply("Please enter the amount of messages that you want to clear!");
if(isNaN(args[0])) return message.reply("Please enter a real number!");
if(args[0] > 100) return message.reply("You cannot delete more than 100 messages!");
if(args[0] < 1) return message.reply("You must delete at least one message!");
await message.channel.messages.fetch({limit: args[0]}).then (messages =>{
message.channel.bulkDelete(messages);
})
}
}
谁能告诉我我做错了什么?我似乎无法在我的代码中找到问题。 机器人的音乐部分工作正常,其他命令也工作正常,但我添加了音乐部分,现在 clear 不起作用,在我添加音乐命令之前它工作正常。
答案 0 :(得分:0)
我想通了(facepalm)我忘了为音乐机器人编写 leave 命令,我使用 clear 命令的开头来制作 module.exports
部分,所以 leave.js
文件是在文件中命名为 clear。