Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { SlashCommandBuilder } = require("discord.js");
- const Schema = require("../../Schemas.js/jointocreatechannels");
- module.exports = {
- data: new SlashCommandBuilder()
- .setName("vc-transfer")
- .setDescription("Transfer the join to create channel to someone else")
- .addUserOption(option => option
- .setName("user")
- .setDescription("the user you wanz give you voice channel")
- .setRequired(true)
- ),
- async execute (interaction, client) {
- const transfer = interaction.options.getMember("user");
- const data = await Schema.findOne({ User: interaction.user.id, Guild: interaction.guild.id });
- const data2 = await Schema.findOne({ User: transfer.id, Guild: interaction.guild.id});
- if (data2) {
- return await interaction.reply({
- content: "This user already has a voice channel, or isnt in your voice channel!",
- ephemeral: true
- })
- };
- if (data) {
- await Schema.create({
- User: transfer.id,
- Channel: data.Channel,
- Guild: interaction.guild.id
- }).catch(err => {
- return interaction.reply({
- content: "There was an Error while transfering your voice channel",
- ephemeral: true
- })
- });
- await Schema.deleteMany({ User: interaction.user.id, Guild: interaction.guild.id}).catch(err => {
- return interaction.reply({
- content: "There was an Error while transfering your voice channel",
- ephemeral: true
- })
- });
- const channel = data.Channel;
- const channelx = await interaction.guild.channels.cache.get(`${channel}`);
- channelx.edit({
- name: `${transfer.user.username}'s-room`,
- })
- await interaction.reply({
- content: `\`Transfer Successfull!\` Transfer to <@${transfer.id}>!`,
- ephemeral: true
- }).catch(err => {
- return interaction.reply({
- content: "There was an Error while transfering your voice channel",
- ephemeral: true
- })
- });
- } else if (!data) {
- return await interaction.reply({
- content: "You dont have a valid voice channel!",
- ephemeral: true
- })
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment