Advertisement
Danulsan

Untitled

Jun 20th, 2023
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. const { Client, GatewayIntentBits, PermissionsBitField, MessageEmbed } = require('discord.js');
  2. const { token } = require('./config.json');
  3.  
  4. const prefix = '>';
  5.  
  6. const client = new Client({
  7. intents: [
  8. GatewayIntentBits.Guilds,
  9. GatewayIntentBits.GuildMessages,
  10. GatewayIntentBits.MessageContent,
  11. ],
  12. });
  13.  
  14. client.on('ready', () => {
  15. console.log('Bot is online!');
  16. client.user.setActivity('Subscribe to ZLG', { type: 'WATCHING' });
  17. });
  18.  
  19. // Command Handler
  20. client.on('messageCreate', (message) => {
  21. if (!message.content.startsWith(prefix) || message.author.bot) return;
  22.  
  23. const args = message.content.slice(prefix.length).split(/ +/);
  24. const command = args.shift().toLowerCase();
  25.  
  26. // Commands
  27. // Test Commands
  28. if (command === 'test') {
  29. message.channel.send('Bot is working!');
  30. message.delete().catch(console.error); // Delete the command message
  31. }
  32. if (command === 'ping') {
  33. message.channel.send('Pong!');
  34. message.delete().catch(console.error); // Delete the command message
  35. }
  36. if (command === 'peace') {
  37. message.channel.send(':peace:');
  38. message.delete().catch(console.error); // Delete the command message
  39. }
  40.  
  41. // Ban Command
  42. if (command === 'ban') {
  43. 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]));
  44.  
  45. // if (!message.member.permissions.has(PermissionsBitField.Flags.BanMembers)) return message.channel.send("You do not have permission to ban people in this server!");
  46. message.delete().catch(console.error); // Delete the command message
  47. if (!member) return message.channel.send("You must specify someone in this command!");
  48. message.delete().catch(console.error); // Delete the command message
  49. if (message.member === member) return message.channel.send("You cannot ban yourself!");
  50. message.delete().catch(console.error); // Delete the command message
  51. if (!member.kickable) return message.channel.send("You cannot ban this person!");
  52. message.delete().catch(console.error); // Delete the command message
  53.  
  54. let reason = args.slice(1).join(" ") || "No reason given.";
  55.  
  56. const embed = new MessageEmbed()
  57. .setColor("Blue")
  58. .setDescription(`:white_check_mark: ${member.user.tag} has been **banned** | ${reason}`);
  59.  
  60. const dmEmbed = new MessageEmbed()
  61. .setColor("Blue")
  62. .setDescription(`:white_check_mark: You were **banned** from ${message.guild.name} | ${reason}`);
  63.  
  64. member.send({ embeds: [dmEmbed] }).catch(err => {
  65. console.log(`${member.user.tag} has their DMs turned off and cannot receive the ban message`);
  66. });
  67.  
  68. member.ban().catch(err => {
  69. message.channel.send("There was an error banning this member.");
  70. });
  71.  
  72. message.channel.send({ embeds: [embed] });
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. });
  83.  
  84. // Login bot with token from config.json
  85. client.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement