bugfix: attach to same parent

This commit is contained in:
Baipyrus 2024-02-09 22:59:11 +01:00
parent 4e3cfacfa4
commit daef590b83

View File

@ -17,7 +17,7 @@ const vcPermissionOverwrites = [
PermissionFlagsBits.Speak PermissionFlagsBits.Speak
]; ];
const getChannel = async (member, channels) => { const getChannel = async (member, guildChs, channel) => {
// Check database for existing channel // Check database for existing channel
const ownCh = await VoiceChannel.findOne({ const ownCh = await VoiceChannel.findOne({
where: { where: {
@ -25,14 +25,15 @@ const getChannel = async (member, channels) => {
} }
}); });
if (ownCh !== null) { if (ownCh !== null) {
return await channels.fetch(ownCh.id); return await guildChs.fetch(ownCh.id);
} }
// Create private channel with all permissions // Create private channel with all permissions
const name = member.user.username; const name = member.user.username;
const chName = `${name}${name.toLowerCase().endsWith('s') ? "'" : "'s"} channel`; const chName = `${name}${name.toLowerCase().endsWith('s') ? "'" : "'s"} channel`;
const privCh = await channels.create({ const privCh = await guildChs.create({
name: chName, name: chName,
parent: channel.parent,
type: ChannelType.GuildVoice, type: ChannelType.GuildVoice,
permissionOverwrites: [ permissionOverwrites: [
{ {
@ -77,13 +78,14 @@ const leftVoiceChat = async (state) => {
export const name = Events.VoiceStateUpdate; export const name = Events.VoiceStateUpdate;
export async function execute(oldState, newState) { export async function execute(oldState, newState) {
const { channel } = newState
await leftVoiceChat(oldState); await leftVoiceChat(oldState);
if (!newState.channel) return; if (!channel) return;
// Find channel by id, return if not registered for customs // Find channel by id, return if not registered for customs
const createCh = await VoiceChannel.findOne({ const createCh = await VoiceChannel.findOne({
where: { where: {
id: newState.channel.id, id: channel.id,
create: true create: true
} }
}); });
@ -96,7 +98,7 @@ export async function execute(oldState, newState) {
const channels = newState.guild.channels; const channels = newState.guild.channels;
let step = 'create'; let step = 'create';
try { try {
const privCh = await getChannel(member, channels); const privCh = await getChannel(member, channels, channel);
step = 'move to'; step = 'move to';
// Move user to private channel // Move user to private channel