config.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. const { MessageEmbed, MessageReaction } = require("discord.js");
  2. module.exports = {
  3. name: "config",
  4. description: "Edit the bot settings",
  5. usage: "",
  6. permissions: {
  7. channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
  8. member: ["ADMINISTRATOR"],
  9. },
  10. aliases: ["conf"],
  11. /**
  12. *
  13. * @param {import("../structures/DiscordMusicBot")} client
  14. * @param {import("discord.js").Message} message
  15. * @param {string[]} args
  16. * @param {*} param3
  17. */
  18. run: async (client, message, args, { GuildDB }) => {
  19. let Config = new MessageEmbed()
  20. .setAuthor("Server Config", client.config.IconURL)
  21. .setColor("RANDOM")
  22. .addField("Prefix", GuildDB.prefix, true)
  23. .addField("DJ Role", GuildDB.DJ ? `<@&${GuildDB.DJ}>` : "Not Set", true)
  24. .setDescription(`
  25. What would you like to edit?
  26. :one: - Server Prefix
  27. :two: - DJ Role
  28. `);
  29. let ConfigMessage = await message.channel.send(Config);
  30. await ConfigMessage.react("1️⃣");
  31. await ConfigMessage.react("2️⃣");
  32. let emoji = await ConfigMessage.awaitReactions(
  33. (reaction, user) =>
  34. user.id === message.author.id &&
  35. ["1️⃣", "2️⃣"].includes(reaction.emoji.name),
  36. { max: 1, errors: ["time"], time: 30000 }
  37. ).catch(() => {
  38. ConfigMessage.reactions.removeAll();
  39. Config.setDescription(
  40. "You took too long to respond. Run the command again to edit the settings."
  41. );
  42. ConfigMessage.edit(Config);
  43. });
  44. let isOk = false;
  45. try {
  46. emoji = emoji.first();
  47. } catch {
  48. isOk = true;
  49. }
  50. if (isOk) return; //im idiot sry ;-;
  51. /**@type {MessageReaction} */
  52. let em = emoji;
  53. ConfigMessage.reactions.removeAll();
  54. if (em._emoji.name === "1️⃣") {
  55. await message.channel.send("What do you want to change it to?");
  56. let prefix = await message.channel.awaitMessages(
  57. (msg) => msg.author.id === message.author.id,
  58. { max: 1, time: 30000, errors: ["time"] }
  59. );
  60. if (!prefix.first())
  61. return message.channel.send("You took too long to respond.");
  62. prefix = prefix.first();
  63. prefix = prefix.content;
  64. await client.database.guild.set(message.guild.id, {
  65. prefix: prefix,
  66. DJ: GuildDB.DJ,
  67. });
  68. message.channel.send(
  69. "Successfully saved guild prefix as `" + prefix + "`"
  70. );
  71. } else {
  72. await message.channel.send(
  73. "Please mention the role you want `DJ's` to have."
  74. );
  75. let role = await message.channel.awaitMessages(
  76. (msg) => msg.author.id === message.author.id,
  77. { max: 1, time: 30000, errors: ["time"] }
  78. );
  79. if (!role.first())
  80. return message.channel.send("You took too long to respond.");
  81. role = role.first();
  82. if (!role.mentions.roles.first())
  83. return message.channel.send(
  84. "Please mention the role that you want for DJ's only."
  85. );
  86. role = role.mentions.roles.first();
  87. await client.database.guild.set(message.guild.id, {
  88. prefix: GuildDB.prefix,
  89. DJ: role.id,
  90. });
  91. message.channel.send(
  92. "Successfully saved guild prefix as <@&" + role.id + ">"
  93. );
  94. }
  95. },
  96. SlashCommand: {
  97. options: [
  98. {
  99. name: "Prefix",
  100. description: "Check the bot's prefix",
  101. type: 1,
  102. required: false,
  103. options: [
  104. {
  105. name: "symbol",
  106. description: "Set the bot's prefix",
  107. type: 3,
  108. required: true,
  109. },
  110. ],
  111. },
  112. {
  113. name: "DJRole",
  114. description: "Check the DJ role",
  115. type: 1,
  116. required: false,
  117. options: [
  118. {
  119. name: "role",
  120. description: "Set the DJ role",
  121. type: 8,
  122. required: true,
  123. },
  124. ],
  125. },
  126. ],
  127. run: async (client, interaction, args, { GuildDB }) => {
  128. let config = interaction.data.options[0].name;
  129. let member = await interaction.guild.members.fetch(interaction.user_id);
  130. //TODO: if no admin perms return...
  131. if (config === "prefix") {
  132. //prefix stuff
  133. if (
  134. interaction.data.options[0].options &&
  135. interaction.data.options[0].options[0]
  136. ) {
  137. //has prefix
  138. let prefix = interaction.data.options[0].options[0].value;
  139. await client.database.guild.set(interaction.guild.id, {
  140. prefix: prefix,
  141. DJ: GuildDB.DJ,
  142. });
  143. interaction.send(`The prefix has now been set to \`${prefix}\``);
  144. } else {
  145. //has not prefix
  146. interaction.send(`Prefix of the server is \`${GuildDB.prefix}\``);
  147. }
  148. } else if (config === "djrole") {
  149. //DJ role
  150. if (
  151. interaction.data.options[0].options &&
  152. interaction.data.options[0].options[0]
  153. ) {
  154. let role = interaction.guild.roles.cache.get(
  155. interaction.data.options[0].options[0].value
  156. );
  157. await client.database.guild.set(interaction.guild.id, {
  158. prefix: GuildDB.prefix,
  159. DJ: role.id,
  160. });
  161. interaction.send(
  162. `Successfully changed DJ role of this server to ${role.name}`
  163. );
  164. } else {
  165. /**
  166. * @type {require("discord.js").Role}
  167. */
  168. let role = interaction.guild.roles.cache.get(GuildDB.DJ);
  169. interaction.send(`DJ Role of the server is ${role.name}`);
  170. }
  171. }
  172. },
  173. },
  174. };