const { Collection, MessageActionRow, Modal, TextInputComponent } = require('discord.js')
const {client} = require('../index.js')
const voicechannel = 'tyt id'
const voiceCollection = new Collection();
const renameInput = new TextInputComponent()
.setCustomId('VOICE_RENAME_INPUT')
.setLabel("Новое название комнаты")
.setStyle('SHORT')
.setMinLength(4)
.setMaxLength(21)
.setPlaceholder('>_')
.setRequired(true);
const renameAuctionInput = new MessageActionRow().addComponents(renameInput);
module.exports = {
name: 'voiceStateUpdate',
async execute(oldState, newState) {
const user = await client.users.fetch(newState.id);
if(!oldState.channel && newState.channel.id === voicechannel){
const channel = await newState.guild.channels.create('?• ' + user.tag, {
type: 'GUILD_VOICE',
parent: newState.channel.parent,
});
const { member } = newState
member.voice.setChannel(channel);
voiceCollection.set(user.id, channel.id);
await client.users.fetch(oldState.id)
const renameModal = new Modal()
.setCustomId('VOICE_RENAME_MODAL')
.setTitle('Переименование комнаты')
renameModal.addComponents(renameAuctionInput);
client.on('interactionCreate', async interaction =>{
if(interaction.isButton()){
switch(interaction.customId){
case 'VOICE_RENAME':
return interaction.showModal(renameModal)
default:
return;
}
}
if(!interaction.isModalSubmit) return;
if(interaction.customId === 'VOICE_RENAME_MODAL'){
const newChannelName = interaction.fields.getTextInputValue('VOICE_RENAME_INPUT');
await interaction.deferReply({ ephemeral: true })
interaction.followUp({ content: '**Комната успешно перемеинована.**', ephemeral: true })
if(newState.channel.parentId === 'тут id категории' && newState.id != 'тут id')
await newState.channel.setName(newChannelName)
}
});
}
};