Answer the question
In order to leave comments, you need to log in
Why doesn't the function for creating private rooms work?
Hello, I can't figure out why the bot doesn't create a private room. How should it work?
After I enter a room called "Create a room" , a private room should automatically be created and I should be transferred to it, and after I leave the room it should automatically be deleted.
- index.js
const discord = require("discord.js"),createPrivateRoom = require("./events/createPrivateRoom.js");
var client = new discord.Client();
client.on("ready",()=>{
console.log(`Бот запущен.`);
})
client.on("voiceStateUpdate",(oldMember,newMember)=>{
createPrivateRoom(oldMember,newMember)
})
client.login("Сюда вставляю токен от бота");
var servers = {};
module.exports = function(oM, nM) {
if (nM.voiceChannel) {
if (nM.voiceChannel.name == "Создать комнату") {
nM.voiceChannel.guild
.createChannel("Приват", {
type: "VOICE",
parent: "774056518051561482",
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();
}
}
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question