I’m working on a Discord bot and having trouble with some commands. The assistance command and cleanup command aren’t responding when I try to use them. Other commands like kick, ping, ban and echo are working fine though. I also want to add console logging whenever someone uses a command but I’m not sure how to implement that. Can anyone help me figure out what’s wrong?
bot.on("message", async msg => {
// Handle all incoming messages
// Skip messages from other bots
if(msg.author.bot) return;
// Only process messages that start with our prefix
if(msg.content.indexOf(settings.prefix) !== 0) return;
// Split the message into command and parameters
const params = msg.content.slice(settings.prefix.length).trim().split(/ +/g);
const cmd = params.shift().toLowerCase();
if(cmd === "ping") {
const response = await msg.channel.send("Checking...");
response.edit(`Response time: ${response.createdTimestamp - msg.createdTimestamp}ms. WebSocket: ${Math.round(bot.ping)}ms`);
}
if(cmd === "echo") {
const textToSend = params.join(" ");
msg.delete().catch(err=>{});
msg.channel.send(textToSend);
}
if(cmd === "kick") {
let adminRole = msg.guild.roles.find("name", "[Admin]");
if(msg.member.roles.has(adminRole.id)) {
let targetUser = msg.guild.member(msg.mentions.users.first());
msg.guild.member(targetUser).kick();
msg.channel.sendMessage("User has been kicked.");
} else {
return msg.reply("You don't have permission to kick users.");
}
}
if(cmd === "ban") {
let adminRole = msg.guild.roles.find("name", "[Admin]");
if(msg.member.roles.has(adminRole.id)) {
let targetUser = msg.guild.member(msg.mentions.users.first());
msg.guild.member(targetUser).ban();
msg.channel.sendMessage("User has been banned.");
} else {
return msg.reply("You don't have permission to ban users.");
}
}
if(cmd === "cleanup") {
const messageCount = parseInt(params[0], 10);
if(!messageCount || messageCount < 2 || messageCount > 100)
return msg.reply("Please specify a number between 2 and 100 for messages to remove");
const messages = await msg.channel.fetchMessages({count: messageCount});
msg.channel.bulkDelete(messages)
.catch(error => msg.reply(`Failed to delete messages: ${error}`));
}
if(cmd === "assistance") {
msg.channel.send({embed: {
color: 0x00AE86,
author: {
name: bot.user.username,
icon_url: bot.user.avatarURL
},
title: "Command List",
description: "Available bot commands and their usage",
fields: [{
name: "!assistance",
value: "Shows this help menu (available to all users)"
},
{
name: "!ping",
value: "Displays bot response time and API latency"
},
{
name: "!kick @user",
value: "Removes a user from the server (Admin only)"
},
{
name: "!ban @user",
value: "Permanently bans a user (Admin only)"
},
{
name: "!cleanup [number]",
value: "Bulk deletes messages (currently not working)"
}
],
timestamp: new Date(),
footer: {
text: "Bot Support Team"
}
});
}
});