bot leave voice channel after a while

My bot leaves voice channel after a while so i let him join the vc every 30m but it works only on one server it doesn't work on all servers im going to send my ready.js file because it has the joining vc code
const color = require('chalk')
const { joinVoiceChannel } = require('@discordjs/voice');
const guildSchema = require('../MongoDB/Schema/guildSchema');
const { EmbedBuilder } = require('discord.js');

module.exports = {
name: 'ready',
async execute(client) {
client.guilds.cache.forEach(async(guild) => {
try {
let data = await guildSchema.findOne({ guildId: guild.id }) || null
if(data !== null && data.voiceChannel) channel = guild.channels.cache.get(data?.voiceChannel) || null
if(data !== null) {
setInterval(()=> {
client.VoiceIDS.push(channel?.id)
if(data !== null && data.premium === "None Version") return;
}, 5_000)
if(data.premium === "Plus Version" || data.premium === "Premium Version") {
if(channel === null) return;
setTimeout(()=> {
connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

return console.log(`Connection Started in ${channel.id}`)
})
setInterval(() => {
connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

return console.log(`Connection Started in ${channel.id}`)
}, 60_000 * 30)
}
}
} catch(e) {
console.log(e)
}
})
}
}
const color = require('chalk')
const { joinVoiceChannel } = require('@discordjs/voice');
const guildSchema = require('../MongoDB/Schema/guildSchema');
const { EmbedBuilder } = require('discord.js');

module.exports = {
name: 'ready',
async execute(client) {
client.guilds.cache.forEach(async(guild) => {
try {
let data = await guildSchema.findOne({ guildId: guild.id }) || null
if(data !== null && data.voiceChannel) channel = guild.channels.cache.get(data?.voiceChannel) || null
if(data !== null) {
setInterval(()=> {
client.VoiceIDS.push(channel?.id)
if(data !== null && data.premium === "None Version") return;
}, 5_000)
if(data.premium === "Plus Version" || data.premium === "Premium Version") {
if(channel === null) return;
setTimeout(()=> {
connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

return console.log(`Connection Started in ${channel.id}`)
})
setInterval(() => {
connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

return console.log(`Connection Started in ${channel.id}`)
}, 60_000 * 30)
}
}
} catch(e) {
console.log(e)
}
})
}
}
2 Replies
d.js toolkit
d.js toolkit2mo ago
- What are your intents? GuildVoiceStates is required to receive voice data! - Show what dependencies you are using -- generateDependencyReport() is exported from @discordjs/voice. - Try looking at common examples: https://github.com/discordjs/voice-examples. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
M7MD
M7MDOP2mo ago
i think i forgot to copy it wait i will send it again
let channel = null
const color = require('chalk')
const { joinVoiceChannel } = require('@discordjs/voice');
const guildSchema = require('../MongoDB/Schema/guildSchema');
const { EmbedBuilder } = require('discord.js');

module.exports = {
name: 'ready',
async execute(client) {
client.guilds.cache.forEach(async(guild) => {
try {
let data = await guildSchema.findOne({ guildId: guild.id }) || null
if(data !== null && data.voiceChannel) channel = guild.channels.cache.get(data?.voiceChannel) || null
if(data !== null) {
setInterval(()=> {
client.VoiceIDS.push(channel?.id)
if(data !== null && data.premium === "None Version") return;
}, 5_000)
if(data.premium === "Plus Version" || data.premium === "Premium Version") {
if(channel === null) return;
setTimeout(()=> {
connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

return console.log(`Connection Started in ${channel.id}`)
})
setInterval(() => {
connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

return console.log(`Connection Started in ${channel.id}`)
}, 60_000 * 30)
}
}
} catch(e) {
console.log(e)
}
})
}
}
let channel = null
const color = require('chalk')
const { joinVoiceChannel } = require('@discordjs/voice');
const guildSchema = require('../MongoDB/Schema/guildSchema');
const { EmbedBuilder } = require('discord.js');

module.exports = {
name: 'ready',
async execute(client) {
client.guilds.cache.forEach(async(guild) => {
try {
let data = await guildSchema.findOne({ guildId: guild.id }) || null
if(data !== null && data.voiceChannel) channel = guild.channels.cache.get(data?.voiceChannel) || null
if(data !== null) {
setInterval(()=> {
client.VoiceIDS.push(channel?.id)
if(data !== null && data.premium === "None Version") return;
}, 5_000)
if(data.premium === "Plus Version" || data.premium === "Premium Version") {
if(channel === null) return;
setTimeout(()=> {
connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

return console.log(`Connection Started in ${channel.id}`)
})
setInterval(() => {
connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

return console.log(`Connection Started in ${channel.id}`)
}, 60_000 * 30)
}
}
} catch(e) {
console.log(e)
}
})
}
}
first line so i need to repeat this code to make it use different values ? no need i will try that im sorry i went to eat, which variable you mean? for now it works but i will come back tomorrow to check or after an hour it works but there is something else, how to make if someone moves to a specific the bot knows and sends in console: Move ok ty

Did you find this page helpful?