Aaron
Explore posts from serversDIAdiscord.js - Imagine an app
•Created by Aaron on 1/29/2024 in #djs-voice
Permission Overwrites on Voice Channels
I set permission overwrites for a voice channel and they do apply, yet they dont seem to take effect at all.
Here is my current code of me making the channel and setting the permissions.
import { Listener } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';
import { ChannelType, OverwriteType, Snowflake, VoiceState } from 'discord.js';
@ApplyOptions<Listener.Options>({
name: 'voiceStateUpdate',
})
export class VoiceStateUpdate extends Listener {
channels: Set<Snowflake> = new Set<Snowflake>();
async run(old_state: VoiceState, new_state: VoiceState) {
const channel_id = '1201376611786817566';
const category_id = '1201376440332079124';
if (new_state.channelId === channel_id) {
try {
const new_channel = await old_state.guild.channels.create({
name: `${old_state.member?.user.username} | private`,
type: ChannelType.GuildVoice,
parent: category_id,
userLimit: 2,
permissionOverwrites: [
{
allow: ['ManageChannels', 'ManageRoles', 'Connect'],
type: OverwriteType.Member,
id: old_state.member?.id!,
},
],
});
await old_state.setChannel(
new_channel,
'voice channel was created by them',
);
console.log(
`Here is the channel permissions:\n`,
new_channel.permissionOverwrites.cache.toJSON(),
);
this.channels.add(new_channel.id);
} catch (err) {
this.container.logger.error(err);
}
}
if (
old_state.channel &&
this.channels.has(old_state.channelId!) &&
old_state.channel?.members.size! <= 0
) {
await old_state.channel!.delete('Everyone left the voice channel');
}
return;
}
}
import { Listener } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';
import { ChannelType, OverwriteType, Snowflake, VoiceState } from 'discord.js';
@ApplyOptions<Listener.Options>({
name: 'voiceStateUpdate',
})
export class VoiceStateUpdate extends Listener {
channels: Set<Snowflake> = new Set<Snowflake>();
async run(old_state: VoiceState, new_state: VoiceState) {
const channel_id = '1201376611786817566';
const category_id = '1201376440332079124';
if (new_state.channelId === channel_id) {
try {
const new_channel = await old_state.guild.channels.create({
name: `${old_state.member?.user.username} | private`,
type: ChannelType.GuildVoice,
parent: category_id,
userLimit: 2,
permissionOverwrites: [
{
allow: ['ManageChannels', 'ManageRoles', 'Connect'],
type: OverwriteType.Member,
id: old_state.member?.id!,
},
],
});
await old_state.setChannel(
new_channel,
'voice channel was created by them',
);
console.log(
`Here is the channel permissions:\n`,
new_channel.permissionOverwrites.cache.toJSON(),
);
this.channels.add(new_channel.id);
} catch (err) {
this.container.logger.error(err);
}
}
if (
old_state.channel &&
this.channels.has(old_state.channelId!) &&
old_state.channel?.members.size! <= 0
) {
await old_state.channel!.delete('Everyone left the voice channel');
}
return;
}
}
6 replies