Answer the question
In order to leave comments, you need to log in
How to remove channel deletion after the creator exits?
Hello! I would like to know how to make it so that when the creator of a "private" room leaves, the channel is not deleted. Such a system is in the VoiceMaster bot, and in the bots on the Tenderly 89Squad servers. And then my bot, when the creator of the room leaves, the room is deleted and throws everyone out. I would like that if there are still users, then the room is not deleted.
var servers = {};
module.exports = function(oM, nM) {
if (nM.voiceChannel) {
//если комнаты для создания приваток не существует
if (
!nM.voiceChannel.guild.channels.find(
channel => channel.name == "создать приват"
)
) {
nM.voiceChannel.guild
.createChannel(
"создать приват",
{
type: "VOICE",
permissionOverwrites: [
{
id: nM.guild.id,
deny: ["ADMINISTRATOR", "SPEAK"],
allow: ["CONNECT"]
}
]
},
{ reason: "Создан канал для приватных комнат" }
)
.then(() => {
nM.voiceChannel.guild.channels
.find(channel => channel.name == "создать приват")
.setUserLimit(1, "Канал для создания приватных комнат");
});
}
//создаём приватку если пользователь зайдёт в канал
if (nM.voiceChannel.name == "создать приват") {
nM.voiceChannel.guild
.createChannel("Приват", {
type: "VOICE",
parent: "665266615423598602",
permissionOverwrites: [
{
id: nM.guild.id,
deny: ["ADMINISTRATOR"],
allow: ["CONNECT", "SPEAK", "VIEW_CHANNEL"]
}
]
})
.then(room => {
nM.setVoiceChannel(room.id);
nM.voiceChannel.guild.channels
.find(channel => channel.id == room.id)
.overwritePermissions(nM, {
KICK_MEMBERS: true,
MANAGE_CHANNELS: true
});
if (!servers[nM.guild.id]) servers[nM.guild.id] = {};
if (!servers[nM.guild.id].voiceMember)
servers[nM.guild.id].voiceMember = {};
if (!servers[nM.guild.id].voiceMember[nM.id])
servers[nM.guild.id].voiceMember[nM.id] = {};
if (!servers[nM.guild.id].voiceMember[nM.id].room)
servers[nM.guild.id].voiceMember[nM.id].room = room.id;
servers[nM.guild.id].voiceMember[nM.id].room = room.id;
if (!servers[nM.guild.id].voiceMember[nM.id].interval)
servers[nM.guild.id].voiceMember[nM.id].interval = {};
servers[nM.guild.id].voiceMember[nM.id].interval = setInterval(() => {
if (nM.voiceChannel) {
if (
servers[nM.guild.id].voiceMember[nM.id].room !=
nM.voiceChannel.id
) {
nM.voiceChannel.guild.channels
.find(
channel =>
channel.id == servers[nM.guild.id].voiceMember[nM.id].room
)
.delete();
clearInterval(servers[nM.guild.id].voiceMember[nM.id].interval);
}
} else if (!nM.voiceChannel) {
//oM.voiceChannel.guild.channels.find(channel=>channel.id == servers[nM.guild.id].voiceMember[nM.id].room).delete();
clearInterval(servers[nM.guild.id].voiceMember[nM.id].interval);
}
}, 3000);
});
}
}
//При выходе из канала, удаление приват комнаты
if (!nM.voiceChannel) {
if (!servers[nM.guild.id]) servers[nM.guild.id] = {};
if (!servers[nM.guild.id].voiceMember)
servers[nM.guild.id].voiceMember = {};
if (!servers[nM.guild.id].voiceMember[nM.id])
servers[nM.guild.id].voiceMember[nM.id] = {};
if (!servers[nM.guild.id].voiceMember[nM.id].room)
servers[nM.guild.id].voiceMember[nM.id].room = 0;
if (!oM.voiceChannel) return;
if (servers[nM.guild.id].voiceMember[nM.id].room == oM.voiceChannel.id) {
oM.voiceChannel.guild.channels
.find(
channel => channel.id == servers[nM.guild.id].voiceMember[nM.id].room
)
.delete();
}
}
};
- main code.const discord = require("discord.js"),
createPrivateRoom = require("./events/createPrivateRoom.js");
var client = new discord.Client();
client.on("ready", () => {
console.log(`Привет, ${client.user.username} онлайн!`);
client.user.setPresence({
status: "online",
game: {
name: "за приватами",
type: "WATCHING"
}
});
});
client.on("voiceStateUpdate", (oldMember, newMember) => {
createPrivateRoom(oldMember, newMember);
});
client.login("токен");
- index.js Answer the question
In order to leave comments, you need to log in
To make a !pkick command, you need to check for arguments, then change the channel permissions for the member, and then disconnect him from the channel (forcibly).
And to remove the fact that the private is deleted - just remove the extra code that deletes the private.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question