Aaron
Aaron
Explore posts from servers
DIAdiscord.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.
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;
}
}
Here is my current code of me making the channel and setting the permissions.
6 replies
SIASapphire - Imagine a framework
Created by Aaron on 1/29/2024 in #sapphire-support
Encountering Error `TypeError: emitter.getMaxListeners is not a function`
No description
16 replies
SIASapphire - Imagine a framework
Created by Aaron on 1/24/2024 in #sapphire-support
How do you register paths for pieces? Also have an additional question when this one is solved.
No description
67 replies