Good Afternoon,
first off I apologize for my lack of knowledge when it comes to Java Script. I am trying to fill a need for one of our servers without exactly knowing how 😀 The end goal is to kick a user once they received a specific role called “Inactive”.
Figure i’d start with creating a bot that kicks a user if you ‘kick @username’. These are the files I have:
Config.json:
{
"token": "(mytoken, which i'm obviously not posting :D)"
}
Index.js:
// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');
// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
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 === 'kick'){
client.commands.get('kick').execute(message, args);
}
});
client.login(token);
package.json:
{
"name": "kickbyrole",
"version": "1.0.0",
"description": "Bot to kick based on discord role",
"main": "index.js",
"author": "Tri",
"dependencies": {
"@discordjs/builders": "^0.12.0",
"@discordjs/rest": "^0.3.0",
"discord-api-types": "^0.28.0",
"discord-prefix": "^3.0.0",
"discord.io": "^2.5.3",
"discord.js": "^13.6.0",
"winston": "^3.6.0"
},
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"license": "ISC"
}
kick.js:
module.exports = {
name: 'kick',
description: "This command kicks a member!",
execute(message, args){
const target = message.mentions.users.first();
if(target){
const memberTarget = message.guild.members.cache.get(target.id);
memberTarget.kick();
message.channel.send("User has been kicked");
}else{
message.channel.send("You couldn't kick that member");
}
}
}
I can “node .” to initiate it without error. My bot shows online.. but nothing happens when I try to !kick @username.
Two asks.. a) what am I missing for my bot to work and b) what do I need to change for it to kick based off user role? So like ‘kick @role’
Appreciate all your time and help!
Cheers
Tri