Advertisement
Guest User

Discord.js

a guest
Oct 17th, 2019
2,688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =const Discord = require('discord.js')
  2. const client = new Discord.Client();
  3.  
  4. client.on('ready', () => {
  5.     console.log('ready');
  6.   });
  7.  
  8. client.on('message', message => {
  9.     //console.log(message.content);
  10.  
  11.     if(message.content.startsWith(`$kick`)) {
  12.         //message.channel.send("kick")
  13.  
  14. let member = message.mentions.members.first();
  15. member.kick().then((member) => {
  16. message.channel.send("**Kick completed**")
  17.   })
  18.    
  19.       }
  20.   });
  21.  
  22. client.on('message', message => {
  23.     //console.log(message.content);
  24.  
  25.     if(message.content.startsWith(`$ban`)) {
  26.         //message.channel.send("ban")
  27.  
  28. let member = message.mentions.members.first();
  29. member.ban().then((member) => {
  30. message.channel.send("**BAN completed**")
  31.   })
  32.    
  33.       }
  34.   });
  35.  
  36. client.on('ready', () => {
  37.     var generalChannel = client.channels.get("631749384790343691") // Replace with known channel ID
  38.     generalChannel.send("PatrickTheStar is now **online!**")  
  39.   });
  40.  
  41. client.on('message', (receivedMessage) => {
  42.     if (receivedMessage.author == client.user) { // Prevent bot from responding to its own messages
  43.         return
  44.     }
  45.  
  46.     // You can copy/paste the actual unicode emoji in the code (not _every_ unicode emoji works)
  47.     receivedMessage.react("👍")
  48.     receivedMessage.react("😎")
  49.     // Unicode emojis: https://unicode.org/emoji/charts/full-emoji-list.html
  50.  
  51.     // Get every custom emoji from the server (if any) and react with each one
  52.     receivedMessage.guild.emojis.forEach(customEmoji => {
  53.         console.log(`Reacting with custom emoji: ${customEmoji.name} (${customEmoji.id})`)
  54.         receivedMessage.react(customEmoji)
  55.     })
  56.     // If you know the ID of the custom emoji you want, you can get it directly with:
  57.     // let customEmoji = receivedMessage.guild.emojis.get(emojiId)
  58. });
  59.  
  60. client.on('ready', () => {
  61.     // Set bot status to: "Playing with JavaScript"
  62.     client.user.setActivity("Public Beta Testing!")
  63.  
  64.     // Alternatively, you can set the activity to any of the following:
  65.     // PLAYING, STREAMING, LISTENING, WATCHING
  66.     // For example:
  67.     // client.user.setActivity("TV", {type: "WATCHING"})
  68. });
  69.  
  70.  
  71. client.on('message', (receivedMessage) => {
  72.     if (receivedMessage.author == client.user) { // Prevent bot from responding to its own messages
  73.         return
  74.     }
  75.    
  76.     if (receivedMessage.content.startsWith("$")) {
  77.         processCommand(receivedMessage)
  78.     }
  79. })
  80.  
  81. function processCommand(receivedMessage) {
  82.     let fullCommand = receivedMessage.content.substr(1) // Remove the leading exclamation mark
  83.     let splitCommand = fullCommand.split(" ") // Split the message up in to pieces for each space
  84.     let primaryCommand = splitCommand[0] // The first word directly after the exclamation is the command
  85.     let arguments = splitCommand.slice(1) // All other words are arguments/parameters/options for the command
  86.  
  87.     console.log("Command received: " + primaryCommand)
  88.     console.log("Arguments: " + arguments) // There may not be any arguments
  89.  
  90.     if (primaryCommand == "help") {
  91.         helpCommand(arguments, receivedMessage)
  92.     } else if (primaryCommand == "multiply") {
  93.         multiplyCommand(arguments, receivedMessage)
  94.     } else {
  95.         receivedMessage.channel.send("I don't understand the command. Try `$help` or `$multiply`")
  96.     }
  97. }
  98.  
  99. function helpCommand(arguments, receivedMessage) {
  100.     if (arguments.length > 0) {
  101.         receivedMessage.channel.send("It looks like you might need help with " + arguments)
  102.     } else {
  103.         receivedMessage.channel.send("I'm not sure what you need help with. Try `$help [topic]`")
  104.     }
  105. }
  106.  
  107. function multiplyCommand(arguments, receivedMessage) {
  108.     if (arguments.length < 2) {
  109.         receivedMessage.channel.send("Not enough values to multiply. Try `!multiply 2 4 10` or `!multiply 5.2 7`")
  110.         return
  111.     }
  112.     let product = 1
  113.     arguments.forEach((value) => {
  114.         product = product * parseFloat(value)
  115.     })
  116.     receivedMessage.channel.send("The product of " + arguments + " multiplied together is: " + product.toString())
  117. }
  118.  
  119. client.on('ready', () => {
  120.     // List servers the bot is connected to
  121.     console.log("Servers:")
  122.     client.guilds.forEach((guild) => {
  123.         console.log(" - " + guild.name)
  124.     })
  125. })
  126. client.on('message', message => {
  127.  //console.log(message.content);
  128.  
  129.  if(message.content.startsWith(`$test`)) {
  130.         message.channel.send("test")
  131.   })
  132.    
  133.       }
  134.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement