toowake

vc-transfer

Jun 21st, 2023
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. const { SlashCommandBuilder } = require("discord.js");
  2. const Schema = require("../../Schemas.js/jointocreatechannels");
  3.  
  4. module.exports = {
  5. data: new SlashCommandBuilder()
  6. .setName("vc-transfer")
  7. .setDescription("Transfer the join to create channel to someone else")
  8. .addUserOption(option => option
  9. .setName("user")
  10. .setDescription("the user you wanz give you voice channel")
  11. .setRequired(true)
  12. ),
  13.  
  14. async execute (interaction, client) {
  15. const transfer = interaction.options.getMember("user");
  16. const data = await Schema.findOne({ User: interaction.user.id, Guild: interaction.guild.id });
  17. const data2 = await Schema.findOne({ User: transfer.id, Guild: interaction.guild.id});
  18.  
  19. if (data2) {
  20. return await interaction.reply({
  21. content: "This user already has a voice channel, or isnt in your voice channel!",
  22. ephemeral: true
  23. })
  24. };
  25.  
  26. if (data) {
  27. await Schema.create({
  28. User: transfer.id,
  29. Channel: data.Channel,
  30. Guild: interaction.guild.id
  31. }).catch(err => {
  32. return interaction.reply({
  33. content: "There was an Error while transfering your voice channel",
  34. ephemeral: true
  35. })
  36. });
  37. await Schema.deleteMany({ User: interaction.user.id, Guild: interaction.guild.id}).catch(err => {
  38. return interaction.reply({
  39. content: "There was an Error while transfering your voice channel",
  40. ephemeral: true
  41. })
  42. });
  43.  
  44. const channel = data.Channel;
  45. const channelx = await interaction.guild.channels.cache.get(`${channel}`);
  46.  
  47. channelx.edit({
  48. name: `${transfer.user.username}'s-room`,
  49. })
  50.  
  51. await interaction.reply({
  52. content: `\`Transfer Successfull!\` Transfer to <@${transfer.id}>!`,
  53. ephemeral: true
  54. }).catch(err => {
  55. return interaction.reply({
  56. content: "There was an Error while transfering your voice channel",
  57. ephemeral: true
  58. })
  59. });
  60. } else if (!data) {
  61. return await interaction.reply({
  62. content: "You dont have a valid voice channel!",
  63. ephemeral: true
  64. })
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment