- Joined
- January 2, 2021
- Messages
- 545
- Points
- 88
- Age
- 16
- IGN
- Avdan_Foxer
So it's simple we make a bot in javascript, but there's a twist I will be adding codes provided by you guys so let's start with a basic framework and no modules (except for node modules and discord.js)
if I do make any mistakes please correct me I'm careless lol, this will continue for 30 days and on the final day, I will prob release this bot or make a repository so everyone can clone this
Main.js
Edit on 16:43 GMT 12+ to add a Very Basic command handler
Edit on 16:53 Gmt 12+ Addded Bot Status (psst give me a good status quote)
Edit on 16:47 GMT 12+ Fixed a Bug with max listeners
config.json
rest node modules and package.json will be already installed if u have done npm i discord.js in the console
if I do make any mistakes please correct me I'm careless lol, this will continue for 30 days and on the final day, I will prob release this bot or make a repository so everyone can clone this
Main.js
Edit on 16:43 GMT 12+ to add a Very Basic command handler
Edit on 16:53 Gmt 12+ Addded Bot Status (psst give me a good status quote)
Edit on 16:47 GMT 12+ Fixed a Bug with max listeners
JavaScript:
Discord = require('discord.js');
const config = require('./config.json');
const client = new Discord.Client();
const command = require('./command')
client.on('ready', () => {
console.log(`Logged in as user ${client.user.tag}!`);
command(client, 'ban', (message) => {
const { member, mentions } = message
const tag = `<@${member.id}>`
if (
member.hasPermission('ADMINISTRATOR') ||
member.hasPermission('BAN_MEMBERS')
) {
const target = mentions.users.first()
if (target) {
const targetMember = message.guild.members.cache.get(target.id)
targetMember.ban()
message.channel.send(`${tag} That user has been banned , hmmm`)
} else {
message.channel.send(`${tag} kiddo , Please specify someone to ban.`)
}
} else {
message.channel.send(
`${tag} Sorry Pal you don't have a permission node BAN_MEMBER , so cant run this command for now...`
)
}
})
command(client, 'kick', (message) => {
const { member, mentions } = message
const tag = `<@${member.id}>`
if (
member.hasPermission('ADMINISTRATOR') ||
member.hasPermission('KICK_MEMBERS')
) {
const target = mentions.users.first()
if (target) {
const targetMember = message.guild.members.cache.get(target.id)
targetMember.kick()
message.channel.send(`${tag} That user has kicked`)
} else {
message.channel.send(`${tag} Please specify someone to kick.`)
}
} else {
message.channel.send(
`${tag} again you don't have permission node KICK_MEMBER, good luck on getting that permission`
)
}
})
})
});
client.on("ready", () => {
client.user.setPresence({ activity: { name:"Watching 80k Jartex Members!" }, status: "dnd" })
})
client.on('interaction', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
});
client.login(config.token)
JavaScript:
//this is a basic cammand handler which i always use for simple stuff
const { prefix } = require('./config.json')
module.exports = (client, aliases, callback) => {
if (typeof aliases === 'string') {
aliases = [aliases]
}
client.on('message', (message) => {
const { content } = message
aliases.forEach((alias) => {
const command = `${prefix}${alias}`
if (content.startsWith(`${command} `) || content === command) {
console.log(`Running the command ${command} on client ${client.user.tag}`)
callback(message)
}
})
})
}
config.json
JSON:
{
"token": "Discord bot token",
"prefix":"?"
}
rest node modules and package.json will be already installed if u have done npm i discord.js in the console
Last edited: