ardittristan

Untitled

Dec 3rd, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. const Discord = require("discord.js");
  2. const client = new Discord.Client();
  3. const config = require("./config.json");
  4.  
  5. client.login(config.token);
  6.  
  7. client.on("ready", () => {
  8. console.log("Booted");
  9. });
  10.  
  11. // commands
  12. client.on("message", (message) => {
  13. if (!message.content.startsWith(config.prefix) || message.author.bot) return;
  14.  
  15. const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  16. const command = args.shift().toLowerCase();
  17. const guild = message.guild;
  18. const lobbyVc = guild.channels.get(config.lobbyId);
  19.  
  20. // create a vc
  21. if (command === "createvc") {
  22. if (message.member.voiceChannelID === lobbyVc.id) { // checks if the user is in the lobby
  23. if (args[0] === "public") {
  24. guild.createChannel(message.member.username, "voice").then(createdChannel => {
  25. createdChannel.edit({
  26. parent: config.parentId
  27. });
  28. message.member.setVoiceChannel(createdChannel);
  29. });
  30. }
  31. else
  32. if (args[0] === "private") {
  33. guild.createChannel(message.member.username, "voice", [{id: guild.id, deny: ["CONNECT"]}]).then(createdChannel => {
  34. createdChannel.edit({
  35. parent: config.parentId
  36. });
  37. message.member.setVoiceChannel(createdChannel);
  38. });
  39. }
  40. else {
  41. message.channel.send("Please specify if the channel is public or private.");
  42. }
  43. }
  44. else {
  45. message.channel.send("Please join " + lobbyVc.name + " to create a channel.");
  46. }
  47. }
  48. else // rename a vc
  49. if (command === "renamevc") {
  50. if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is allowed to rename vc
  51. console.log("<" + message.member.id + "> renamed <" + message.member.voiceChannel.name + "> into <" + message.content.slice(config.prefix.length + 9) + ">");
  52. message.member.voiceChannel.setName(message.content.slice(config.prefix.length + 9));
  53. }
  54. else {
  55. message.channel.send("You don't have the permission to rename this vc.");
  56. }
  57. }
  58. else // allow an user
  59. if (command === "allowuser") {
  60. if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is in a modifyable voice channel
  61. if (guild.members.has(args[0])) {
  62. guild.channel.id(message.member.voiceChannelID).edit({
  63. overwrites: [{
  64. id: args[0],
  65. allowed: ["Connect"]
  66. }]
  67. })
  68. }
  69. else
  70. if (message.mentions.members.first() != undefined) {
  71. guild.channel.id(message.member.voiceChannelID).edit({
  72. overwrites: [{
  73. id: message.mentions.members.first().id,
  74. allowed: ["Connect"]
  75. }]
  76. })
  77. }
  78. else {
  79. message.channel.send("Please attach an user-id or mention to the command.");
  80. }
  81. }
  82. else {
  83. message.channel.send("You are not allowed to allow users in this voice channel.");
  84. }
  85. }
  86. else // disallow user
  87. if (command === "disallowuser") {
  88. if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is in a modifyable voice channel
  89. if (guild.members.has(args[0])) {
  90. guild.channel.id(message.member.voiceChannelID).edit({
  91. overwrites: [{
  92. id: args[0],
  93. deny: ["Connect"]
  94. }]
  95. })
  96. }
  97. else
  98. if (message.mentions.members.first() != undefined) {
  99. guild.channel.id(message.member.voiceChannelID).edit({
  100. overwrites: [{
  101. id: message.mentions.members.first().id,
  102. deny: ["Connect"]
  103. }]
  104. })
  105. }
  106. else {
  107. message.channel.send("Please attach an user-id or mention to the command.");
  108. }
  109. }
  110. else {
  111. message.channel.send("You are not allowed to deny users in this voice channel.");
  112. }
  113. }
  114. });
Advertisement
Add Comment
Please, Sign In to add comment