TypeError

I am currently on a discord music bot which has a 247 command and for some reason the bot just times out after few hours, so I am trying to code so that if by chance the bot does leave or gets disconnet it will attempt to rejoin the voice chat, but I am running to a TypeError: realVoiceChannel.join is not a function;
10 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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!
grass
grass15mo ago
pretty sure voicechannel#join doesnt exist
it is rude
it is rudeOP15mo ago
is there a alt way, I could make my bot attempt a rejoin?
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs15mo ago
guide Library: Voice Connections read more
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
it is rude
it is rudeOP15mo ago
Thats 2 different ways, making it join and reconnect itself. to my understanding the only platform that will be against the TOS is youtube. but thanks for the heads up. well I've tried that but no it doesn't work. using the code for the join command, its weird because when I use the dc command its able to rejoin the vc but when I manually disconnect it from vc it is unable to join back saying ID is not found (log), but I did more debugging and the ID the bot pulls from the DB is the same. also DiscordAPIError[10008]: Unknown Message at handleErrors (/home/container/node_modules/@discordjs/rest/dist/index.js:640:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async SequentialHandler.runRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:1021:23) at async SequentialHandler.queueRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:862:14) at async REST.request (/home/container/node_modules/@discordjs/rest/dist/index.js:1387:22) at async MessageManager.delete (/home/container/node_modules/discord.js/src/managers/MessageManager.js:255:5) at async Message.delete (/home/container/node_modules/discord.js/src/structures/Message.js:816:5) { requestBody: { files: undefined, json: undefined }, rawError: { message: 'Unknown Message', code: 10008 }, code: 10008, status: 404, method: 'DELETE', url: 'https://discord.com/api/v10/channels/958143858280112191/messages/1148672688961888337' } I don't understand why I keep thing this API error, I have the bot's perm, the message ID which the bot is trying to delete and such. Log after disconnect the bot manually
VoiceChannel ID from DB: 1016197435925741600
Fetched voiceChannel object: {
"type": 13,
"guild": "1013525707919478784",
"guildId": "1013525707919478784",
"parentId": "1013525708443762740",
"permissionOverwrites": [],
"messages": [],
"nsfw": false,
"flags": 0,
"id": "1016197435925741600",
"name": "Assia",
"rawPosition": 0,
"rtcRegion": null,
"bitrate": 64000,
"userLimit": 10000,
"videoQualityMode": null,
"lastMessageId": "1148655757114482875",
"rateLimitPerUser": 0,
"topic": null,
"createdTimestamp": 1662350748760
}
No such voice channel found with ID: 1016197435925741600
VoiceChannel ID from DB: 1016197435925741600
Fetched voiceChannel object: {
"type": 13,
"guild": "1013525707919478784",
"guildId": "1013525707919478784",
"parentId": "1013525708443762740",
"permissionOverwrites": [],
"messages": [],
"nsfw": false,
"flags": 0,
"id": "1016197435925741600",
"name": "Assia",
"rawPosition": 0,
"rtcRegion": null,
"bitrate": 64000,
"userLimit": 10000,
"videoQualityMode": null,
"lastMessageId": "1148655757114482875",
"rateLimitPerUser": 0,
"topic": null,
"createdTimestamp": 1662350748760
}
No such voice channel found with ID: 1016197435925741600
const { EmbedBuilder } = require("discord.js");
const delay = require("delay");
const AvonClientEvent = require("../../structures/Eventhandler");

class AvonVoiceStateUpdate extends AvonClientEvent {
get name() {
return 'voiceStateUpdate';
}

async run(os, ns) {
console.log('voiceStateUpdate event fired');

let player = this.client.poru.players.get(ns.guild.id);
if (!player && os.id !== this.client.user.id) return;

let db = await this.client.data.get(`${ns.guild.id}-247`);
if (!db || db === null) this.client.data.set(`${ns.guild.id}-247`, `disabled`);

console.log(`24/7 Mode: ${db}`);

if (os.id === this.client.user.id && !ns.channelId && db === 'enabled') {
const voiceChannelId = await this.client.data.get(`${ns.guild.id}-voice`);
console.log(`VoiceChannel ID from DB: ${voiceChannelId}`);

try {
const guild = await this.client.guilds.fetch(ns.guild.id);
const voiceChannel = await guild.channels.fetch(voiceChannelId);

console.log(`Fetched voiceChannel object: ${JSON.stringify(voiceChannel, null, 2)}`);

if (voiceChannel && (voiceChannel.type === 'GUILD_VOICE' || voiceChannel.type === 'GUILD_STAGE_VOICE')) {
const botMember = guild.members.cache.get(this.client.user.id);

if (botMember && botMember.voice) {
if (!botMember.voice.channelId || botMember.voice.channelId !== voiceChannelId) {
await delay(2000); // Delay for 2 seconds
await botMember.voice.setChannel(voiceChannelId).catch(err => console.error(`Failed to join the channel: ${err}`));
console.log('Successfully joined the voice channel.');
} else {
console.log('Bot is already in the voice channel.');
}
} else {
console.error(`Bot member or voice state not found in the guild: ${guild.id}`);
}
} else {
console.error(`No such voice channel found with ID: ${voiceChannelId}`);
}
} catch (err) {
console.error(`Failed to fetch or join voice channel: ${err}`);
}
}
}
}

module.exports = AvonVoiceStateUpdate;
const { EmbedBuilder } = require("discord.js");
const delay = require("delay");
const AvonClientEvent = require("../../structures/Eventhandler");

class AvonVoiceStateUpdate extends AvonClientEvent {
get name() {
return 'voiceStateUpdate';
}

async run(os, ns) {
console.log('voiceStateUpdate event fired');

let player = this.client.poru.players.get(ns.guild.id);
if (!player && os.id !== this.client.user.id) return;

let db = await this.client.data.get(`${ns.guild.id}-247`);
if (!db || db === null) this.client.data.set(`${ns.guild.id}-247`, `disabled`);

console.log(`24/7 Mode: ${db}`);

if (os.id === this.client.user.id && !ns.channelId && db === 'enabled') {
const voiceChannelId = await this.client.data.get(`${ns.guild.id}-voice`);
console.log(`VoiceChannel ID from DB: ${voiceChannelId}`);

try {
const guild = await this.client.guilds.fetch(ns.guild.id);
const voiceChannel = await guild.channels.fetch(voiceChannelId);

console.log(`Fetched voiceChannel object: ${JSON.stringify(voiceChannel, null, 2)}`);

if (voiceChannel && (voiceChannel.type === 'GUILD_VOICE' || voiceChannel.type === 'GUILD_STAGE_VOICE')) {
const botMember = guild.members.cache.get(this.client.user.id);

if (botMember && botMember.voice) {
if (!botMember.voice.channelId || botMember.voice.channelId !== voiceChannelId) {
await delay(2000); // Delay for 2 seconds
await botMember.voice.setChannel(voiceChannelId).catch(err => console.error(`Failed to join the channel: ${err}`));
console.log('Successfully joined the voice channel.');
} else {
console.log('Bot is already in the voice channel.');
}
} else {
console.error(`Bot member or voice state not found in the guild: ${guild.id}`);
}
} else {
console.error(`No such voice channel found with ID: ${voiceChannelId}`);
}
} catch (err) {
console.error(`Failed to fetch or join voice channel: ${err}`);
}
}
}
}

module.exports = AvonVoiceStateUpdate;
You can see the ID pulled from DB is the same as the voice channel ID that logs no such ID found
Almeida
Almeida15mo ago
are you using discord.js v13 or v14
d.js docs
d.js docs15mo ago
Version 14 has released! Please update at your earliest convenience. - Update: npm rm discord.js npm i discord.js - Update guide (use CTRL + F to search for the old method or property)
it is rude
it is rudeOP15mo ago
FeelsBadMan is it that causing the bot not to join?
Want results from more Discord servers?
Add your server