Steep
DIAdiscord.js - Imagine an app
•Created by Steep on 8/11/2023 in #djs-questions
Giving a member permission to change permissions in a selected channel
What is supposed to happen:
User gets permission to change permissions in a selected voice channel
What happens:
User does not have permission to change permissions in selected voice channel
code:
moveMember method incase needed:
removeTempChannel method incase needed:
async function addTempChannel(member, guild) {
var channel = await guild.channels.create({
name: member.displayName,
type: ChannelType.GuildVoice,
parent: await JSON.parse(fs.readFileSync("./channels.json", { encoding: "utf8" }))[guild.id].categoryChannel,
permissionOverwrites: [
{
id: member.user.id,
allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.Connect, PermissionsBitField.Flags.ManageChannels, PermissionsBitField.Flags.Administrator]
},
{
id: guild.roles.everyone,
deny: [PermissionsBitField.Flags.Connect]
}
]
});
var removed = false;
await moveMember(member, channel).catch(() => {
removeTempChannel(channel);
removed = true;
});
if(channel.members.size < 1) {
console.log("removing");
removeTempChannel(channel);
removed = true;
}
if(removed) return;
const data = await JSON.parse(fs.readFileSync("./temp_channels.json", { encoding: "utf8" }));
data.push(channel.id);
fs.writeFileSync("./temp_channels.json", JSON.stringify(data));
}
async function addTempChannel(member, guild) {
var channel = await guild.channels.create({
name: member.displayName,
type: ChannelType.GuildVoice,
parent: await JSON.parse(fs.readFileSync("./channels.json", { encoding: "utf8" }))[guild.id].categoryChannel,
permissionOverwrites: [
{
id: member.user.id,
allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.Connect, PermissionsBitField.Flags.ManageChannels, PermissionsBitField.Flags.Administrator]
},
{
id: guild.roles.everyone,
deny: [PermissionsBitField.Flags.Connect]
}
]
});
var removed = false;
await moveMember(member, channel).catch(() => {
removeTempChannel(channel);
removed = true;
});
if(channel.members.size < 1) {
console.log("removing");
removeTempChannel(channel);
removed = true;
}
if(removed) return;
const data = await JSON.parse(fs.readFileSync("./temp_channels.json", { encoding: "utf8" }));
data.push(channel.id);
fs.writeFileSync("./temp_channels.json", JSON.stringify(data));
}
async function moveMember(member, voicechannel) {
return await member.voice.setChannel(voicechannel);
}
async function moveMember(member, voicechannel) {
return await member.voice.setChannel(voicechannel);
}
async function removeTempChannel(channel) {
if(isNullOrUndefined(channel) || isNullOrUndefined(channel.name)) {
console.log("fail");
return;
}
if(isNullOrUndefined(deleter.get(channel.guild))) deleter.set(channel.guild, new Deleter());
await deleter.get(channel.guild).add(channel);
}
async function removeTempChannel(channel) {
if(isNullOrUndefined(channel) || isNullOrUndefined(channel.name)) {
console.log("fail");
return;
}
if(isNullOrUndefined(deleter.get(channel.guild))) deleter.set(channel.guild, new Deleter());
await deleter.get(channel.guild).add(channel);
}
5 replies