Skip to content

Voice Moderation

nutmeg edited this page Feb 22, 2023 · 3 revisions

Run Down

Discord+PS has multiple ways of moderating VCs that are not currently supported in Discord.JS as heavily

Muting and Unmuting

Compared to Discord.JS muting is a lot simpler only requiring a user
To mute and unmute a user they have to be in a voice channel due to Discord.JS limitations

PSClient.voice.mute(user);

PSClient.voice.unmute(user);

In this example we have a mute command that mutes a user in vc for 5 seconds then unmutes them

PSClient.command({name: "mute"}, async (ctx, cmd) => {
	let user = PSClient.fetchUser(cmd.args[0]);

	PSClient.voice.mute(user);
	console.log("Muted user");

	await PSClient.sleep(5);

	PSClient.voice.unmute(user);
	console.log("Unmuted user");
});

Deafening and Undeafening

Deafening is also a lot simpler than Discord.JS To deafen and undeafen a user they have to be in a voice channel due to Discord.JS limitations

PSClient.voice.deafen(user);

PSClient.voice.undeafen(user);

In this example we have a deafen command that deafens a user in vc for 5 seconds then undeafens them

PSClient.command({name: "deafen"}, async (ctx, cmd) => {
	let user = PSClient.fetchUser(cmd.args[0]);

	PSClient.voice.deafen(user);
	console.log("Deafened user");

	await PSClient.sleep(5);

	PSClient.voice.undeafen(user);
	console.log("Undeafened user");
});

Locking and Unlocking

Locking is a new Discord+PS feature that mutes and deafens, you can lock individual users using PSClient.voice.lockUser() or you can lock entire vcs using PSClient.voice.lock()

PSClient.voice.lock(channel);
PSClient.voice.unlock(channel);

PSClient.voice.lockUser(user);
PSClient.voice.unlockUser(user);

In this example we have a lock command that locks a channel for 5 seconds then unlocks it

PSClient.command({name: "lock"}, async (ctx, cmd) => {
	PSClient.voice.find(user, async (channel) => {
		PSClient.voice.lock(channel);
		
		await PSClient.sleep(5);
		
		PSClient.voice.unlock(channel);
	});
});

Limitations

If you are interested the reason why it's more difficult is because of how Discord.JS handles muting and deafening
In Discord.JS the only way to mute/deafen a user in a voice channel is by finding them in a voice channel and then using user.setMute()
This is how it's handled in Discord+PS:

mute(user) {
	var [psc, client, ctx] = Holder;
	psc.guild.channelF( (channels) => {
		channels.forEach( (channel) => {
			if (channel.members.has(user.id) && channel.type == 2) {
				let vcUser = channel.members.get(user.id);
				voice.setMute(true);
			}
		});
	});
}
unmute(user) {
	var [psc, client, ctx] = Holder;
	psc.guild.channelF( (channels) => {
		channels.forEach( (channel) => {
			if (channel.members.has(user.id) && channel.type == 2) {
				let vcUser = channel.members.get(user.id);
				voice.setMute(false);
			}
		});
	});
}
deafen(user) {
	var [psc, client, ctx] = Holder;
	psc.guild.channelF( (channels) => {
		channels.forEach( (channel) => {
			if (channel.members.has(user.id) && channel.type == 2) {
				let vcUser = channel.members.get(user.id);
				voice.setDeaf(true);
			}
		});
	});
}
undeafen(user) {
	var [psc, client, ctx] = Holder;
	psc.guild.channelF( (channels) => {
		channels.forEach( (channel) => {
			if (channel.members.has(user.id) && channel.type == 2) {
				let vcUser = channel.members.get(user.id);
				voice.setDeaf(false);
			}
		});
	});
}
lockUser(user) {
	var [psc, client, ctx] = Holder;
	psc.guild.channelF( (channels) => {
		channels.forEach( (channel) => {
			if (channel.members.has(user.id) && channel.type == 2) {
				let vcUser = channel.members.get(user.id);
				voice.setMute(true);
				voice.setDeaf(true);
			}
		});
	});
}
unlockUser(user) {
	var [psc, client, ctx] = Holder;
	psc.guild.channelF( (channels) => {
		channels.forEach( (channel) => {
			if (channel.members.has(user.id) && channel.type == 2) {
				let vcUser = channel.members.get(user.id);
				voice.setMute(false);
				voice.setDeaf(false);
			}
		});
	});
}
lock(channel) {
	var [psc, client, ctx] = Holder;
	let vc = client.channels.cache.get(channel.id);
	vc.members.forEach( (user) => {
		user.voice.setMute(true);
		user.voice.setDeaf(true);
	});
}
unlock(channel) {
	var [psc, client, ctx] = Holder;
	let vc = client.channels.cache.get(channel.id);
	vc.members.forEach( (user) => {
		user.voice.setMute(false);
		user.voice.setDeaf(false);
	});
}
Clone this wiki locally