Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client, GatewayIntentBits, PermissionsBitField, MessageEmbed } = require('discord.js');
- const { token } = require('./config.json');
- const prefix = '>';
- const client = new Client({
- intents: [
- GatewayIntentBits.Guilds,
- GatewayIntentBits.GuildMessages,
- GatewayIntentBits.MessageContent,
- ],
- });
- client.on('ready', () => {
- console.log('Bot is online!');
- client.user.setActivity('Subscribe to ZLG', { type: 'WATCHING' });
- });
- // Command Handler
- client.on('messageCreate', (message) => {
- if (!message.content.startsWith(prefix) || message.author.bot) return;
- const args = message.content.slice(prefix.length).split(/ +/);
- const command = args.shift().toLowerCase();
- // Commands
- // Test Commands
- if (command === 'test') {
- message.channel.send('Bot is working!');
- message.delete().catch(console.error); // Delete the command message
- }
- if (command === 'ping') {
- message.channel.send('Pong!');
- message.delete().catch(console.error); // Delete the command message
- }
- if (command === 'peace') {
- message.channel.send(':peace:');
- message.delete().catch(console.error); // Delete the command message
- }
- // Ban Command
- if (command === 'ban') {
- const member = message.mentions.members.first() || message.guild.members.cache.get(args[0]) || message.guild.members.cache.find(x => x.user.username.toLowerCase() === args.slice(0).join(" " || x.user.username === args[0]));
- // if (!message.member.permissions.has(PermissionsBitField.Flags.BanMembers)) return message.channel.send("You do not have permission to ban people in this server!");
- message.delete().catch(console.error); // Delete the command message
- if (!member) return message.channel.send("You must specify someone in this command!");
- message.delete().catch(console.error); // Delete the command message
- if (message.member === member) return message.channel.send("You cannot ban yourself!");
- message.delete().catch(console.error); // Delete the command message
- if (!member.kickable) return message.channel.send("You cannot ban this person!");
- message.delete().catch(console.error); // Delete the command message
- let reason = args.slice(1).join(" ") || "No reason given.";
- const embed = new MessageEmbed()
- .setColor("Blue")
- .setDescription(`:white_check_mark: ${member.user.tag} has been **banned** | ${reason}`);
- const dmEmbed = new MessageEmbed()
- .setColor("Blue")
- .setDescription(`:white_check_mark: You were **banned** from ${message.guild.name} | ${reason}`);
- member.send({ embeds: [dmEmbed] }).catch(err => {
- console.log(`${member.user.tag} has their DMs turned off and cannot receive the ban message`);
- });
- member.ban().catch(err => {
- message.channel.send("There was an error banning this member.");
- });
- message.channel.send({ embeds: [embed] });
- }
- });
- // Login bot with token from config.json
- client.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement