AustinFx_

Discord Bot Source Code

May 13th, 2019
1,677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. const Discord = require('discord.js')
  2. const client = new Discord.Client()
  3.  
  4. client.on('ready', () => {
  5. console.log("Connected as " + client.user.tag)
  6.  
  7. client.user.setActivity("Micheal Reeves", {type: "watching"}) // Status for the bot (Watching, playing, streaming)
  8.  
  9. clients.guilds.forEach((guild) => { // Logs the servers its connected to
  10. console.log(guild.name)
  11. guild.channels.forEach((channel) => {
  12. console.log(` - ${channel.name} ${channel.type} ${channel.id}`)
  13. })
  14. // General channel id: 420363942745997322
  15.  
  16. })
  17.  
  18. let generalChannel = client.channels.get("420363942745997322")
  19. const attachment = new Discord.attachment ("https://www.devdungeon.com/sites/default/static/discord/GetBotToken.PNG")
  20. generalChannel.send(attachment)
  21. })
  22.  
  23. client.on('message', (recievedMessage) => {
  24. if (recievedMessage.author == client.user) {
  25. return
  26. }
  27. recievedMessage.channel.send("Message Recieved," + recievedMessage.author.toString() + recievedMessage.content)
  28.  
  29. //recievedMessage.react("👍")
  30. //To find emojis use these three lines | recievedMessage.guild.emojis.forEach(customEmjoji => {
  31. //console.log(`${customEmoji.name} ${customEmoji.id}`)
  32. //recievedMessage.react(customEmoji)|
  33.  
  34.  
  35. if (recievedMessage.content.startsWith(",,")) {
  36. processCommand(receivedMessage)
  37. }
  38. })
  39.  
  40. function processCommand(recievedMessage){ //Command processing fuction
  41. let fullCommand = recievedMessage.content.substr(1)
  42. let splitCommand = fullCommand.split(" ")
  43. let primaryCommand = splitCommand[0]
  44. let arguments = splitCommand.slice(1)
  45.  
  46. if (primaryCommand == "help"){ //sets ,,help as the primary command
  47. helpCommand(arguments, recievedMessage)
  48. } else if (primaryCommand == "multiply") {
  49. multiplyCommand(arguments, receivedMessage)
  50. } else {
  51. recievedMessage.channel.send("Unknown command. Try `,,help`")
  52. }
  53. }
  54.  
  55. function multiplyCommand(arguments, recievedMessage){ //adds the multiplication command
  56. if (arguments.length < 2){
  57. recievedMessage.channel.send("not enough arguments. Try `,,multiply 2 10`")
  58. return
  59. }
  60. let product = 1
  61. arguments.forEach((value) => {
  62. product = product * parseFloat(value)
  63. })
  64. recievedMessage.channel.send("The product of" + arguments, "is" + product.toString())
  65. }
  66.  
  67. function helpCommand(arguments, recievedMessage){ //adds the help command
  68. if (arguments.length == 0) {
  69. receivedMessage.channel.send("```Please enter what you need help with (,,help [topic])```")
  70. } else {
  71. recievedMessage.channel.send("```It looks like you need help with```" + arguments)
  72. }
  73. }
  74.  
  75. //function processCommand(recievedMessage){
  76.  
  77.  
  78. bot_secret_token = "NTc3MjQ2NjczOTExMTUyNjUw.XNikjg.gC90UkCqyCUa4hV8J5ojcboVSk4"
  79.  
  80. client.login("NTc3MjQ2NjczOTExMTUyNjUw.XNikjg.gC90UkCqyCUa4hV8J5ojcboVSk4")
Advertisement
Add Comment
Please, Sign In to add comment