viki.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Load up the discord.js library
  2. const Discord = require("discord.js");
  3. // Load up the shell command library
  4. var exec = require('child_process').exec;
  5. // Load up the queue library
  6. const Queue = require('./Queue.js');
  7. // Define a function to execute a command
  8. function execute(command, callback)
  9. {
  10. exec(command, function(error, stdout, stderr)
  11. {
  12. callback(stdout);
  13. });
  14. };
  15. // Define a new function to search + replace a char in a string
  16. String.prototype.replaceAll = function(remove, replace)
  17. {
  18. var target = this;
  19. return target.split(remove).join(replace);
  20. };
  21. // Initialize the bot.
  22. const client = new Discord.Client();
  23. // this allows us to define a voice connection with global scope
  24. var connection;
  25. var dispatcher;
  26. // this is the playlist queue for music
  27. var playlist = new Queue();
  28. // Array of music classes users can call (artist, track, etc)
  29. const musicTypes = ['track', 'title', 'song', 'artist', 'album'];
  30. const musicTypesString = "track, title, song, artist, album";
  31. // Here we load the config.json file that contains our token and our prefix values.
  32. const config = require("./config.json");
  33. // config.token contains the bot's token
  34. // config.prefix contains the message prefix.
  35. client.on("ready", () =>
  36. {
  37. // This event will run if the bot starts, and logs in, successfully.
  38. console.log(`Bot has started, with ${client.users.cache.size} users, in ${client.channels.cache.size} channels of ${client.guilds.cache.size} guilds.`);
  39. console.log(`users: ${Array.from(client.users.cache.values()).map(each => each.username)}`);
  40. // Example of changing the bot's playing game to something useful. `client.user` is what the
  41. // docs refer to as the "ClientUser".
  42. client.user.setActivity("Taking Over Chicago");
  43. });
  44. client.on("guildCreate", guild =>
  45. {
  46. // This event triggers when the bot joins a guild.
  47. console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
  48. client.user.setActivity(`Serving ${client.guilds.size} servers`);
  49. });
  50. client.on("guildDelete", guild => {
  51. // this event triggers when the bot is removed from a guild.
  52. console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
  53. client.user.setActivity("Taking Over Chicago");
  54. });
  55. client.on('message', msg => {
  56. if (msg.content === '!ping') {
  57. msg.reply('pong');
  58. channel = msg.guild.channels.cache.find(each => each.name === "General" && each.type === "voice");
  59. if (channel)
  60. {
  61. console.log(channel.name);
  62. channel.join().then(conn =>
  63. {
  64. connection = conn;
  65. console.log('Connected!');
  66. }).catch(console.error);
  67. }
  68. }
  69. });
  70. client.login(config.token);