Can't join voice channel

I am making a background music bot that joins a voice channel and plays, well background music. I copy-pasted the code from the documentation but it refuses to work. What am I doing wrong?
14 Replies
Danial
Danial10mo ago
What documentation, any errors?
Maxzie
Maxzie10mo ago
Documentation: https://discordjs.guide/voice/voice-connections.html#voice-connections Errors: No errors, but bot refuses to respond. Code:
const express = require("express");
const app = express()

app.listen(3000, () => {
console.log("Project started!");
})

app.get("/", (req, res) => {
res.send("Hello world!");
})

const Discord = require("discord.js");
const client = new Discord.Client({ intents: ['Guilds','GuildMessages','MessageContent', 'GuildMessageReactions'] })
const { ActivityType } = require('discord.js');

client.on("messageCreate", message => {
if(message.content === "test") {
message.channel.send("Now playing some awesome background music")
message.channel.send("Music: ???")
const connection = joinVoiceChannel({
channelId: 1144178228550959184,
guildId: 760830214564610048,
adapterCreator: channel.guild.voiceAdapterCreator,
});
}
})


client.login(process.env.token)
const express = require("express");
const app = express()

app.listen(3000, () => {
console.log("Project started!");
})

app.get("/", (req, res) => {
res.send("Hello world!");
})

const Discord = require("discord.js");
const client = new Discord.Client({ intents: ['Guilds','GuildMessages','MessageContent', 'GuildMessageReactions'] })
const { ActivityType } = require('discord.js');

client.on("messageCreate", message => {
if(message.content === "test") {
message.channel.send("Now playing some awesome background music")
message.channel.send("Music: ???")
const connection = joinVoiceChannel({
channelId: 1144178228550959184,
guildId: 760830214564610048,
adapterCreator: channel.guild.voiceAdapterCreator,
});
}
})


client.login(process.env.token)
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
duck
duck10mo ago
1. ids need to be strings 2. you'll need the GuildVoiceStates intent
d.js docs
d.js docs10mo ago
- Discord ids follow the snowflake format: learn more - Discord ids must be represented as strings as they are larger than Number.MAX_SAFE_INTEGER, the largest integer that can be represented in JavaScript
- client.guilds.cache.get(123456789012345678)
+ client.guilds.cache.get("123456789012345678")
- client.guilds.cache.get(123456789012345678)
+ client.guilds.cache.get("123456789012345678")
Maxzie
Maxzie10mo ago
Oh, okay. I tried it, and it still doesn't work. Error:
/home/runner/BackgroundMusicBotRepl-1/index.js:20
const connection = joinVoiceChannel({
^

ReferenceError: joinVoiceChannel is not defined
at Client.<anonymous> (/home/runner/BackgroundMusicBotRepl-1/index.js:20:24)
at Client.emit (node:events:513:28)
at Client.emit (node:domain:489:12)
at MessageCreateAction.handle (/home/runner/BackgroundMusicBotRepl-1/node_modules/discord.js/src/client/actions/MessageCreate.js:28:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/runner/BackgroundMusicBotRepl-1/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/runner/BackgroundMusicBotRepl-1/node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (/home/runner/BackgroundMusicBotRepl-1/node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
at WebSocketManager.emit (/home/runner/BackgroundMusicBotRepl-1/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/home/runner/BackgroundMusicBotRepl-1/node_modules/@discordjs/ws/dist/index.js:1173:51)
repl process died unexpectedly: exit status 1
/home/runner/BackgroundMusicBotRepl-1/index.js:20
const connection = joinVoiceChannel({
^

ReferenceError: joinVoiceChannel is not defined
at Client.<anonymous> (/home/runner/BackgroundMusicBotRepl-1/index.js:20:24)
at Client.emit (node:events:513:28)
at Client.emit (node:domain:489:12)
at MessageCreateAction.handle (/home/runner/BackgroundMusicBotRepl-1/node_modules/discord.js/src/client/actions/MessageCreate.js:28:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/runner/BackgroundMusicBotRepl-1/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/runner/BackgroundMusicBotRepl-1/node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (/home/runner/BackgroundMusicBotRepl-1/node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
at WebSocketManager.emit (/home/runner/BackgroundMusicBotRepl-1/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/home/runner/BackgroundMusicBotRepl-1/node_modules/@discordjs/ws/dist/index.js:1173:51)
repl process died unexpectedly: exit status 1
Code:
const express = require("express");
const app = express()

app.listen(3000, () => {
console.log("Project started!");
})

app.get("/", (req, res) => {
res.send("Hello world!");
})

const Discord = require("discord.js");
const client = new Discord.Client({ intents: ['Guilds','GuildMessages','MessageContent', 'GuildMessageReactions', 'GuildVoiceStates'] })


client.on("messageCreate", message => {
if(message.content === "test") {
message.channel.send("Now playing some awesome background music")
message.channel.send("Music: ???")
const connection = joinVoiceChannel({
channelId: "1144178228550959184",
guildId: "760830214564610048",
adapterCreator: channel.guild.voiceAdapterCreator,
});
}
})


client.login(process.env.token);
const express = require("express");
const app = express()

app.listen(3000, () => {
console.log("Project started!");
})

app.get("/", (req, res) => {
res.send("Hello world!");
})

const Discord = require("discord.js");
const client = new Discord.Client({ intents: ['Guilds','GuildMessages','MessageContent', 'GuildMessageReactions', 'GuildVoiceStates'] })


client.on("messageCreate", message => {
if(message.content === "test") {
message.channel.send("Now playing some awesome background music")
message.channel.send("Music: ???")
const connection = joinVoiceChannel({
channelId: "1144178228550959184",
guildId: "760830214564610048",
adapterCreator: channel.guild.voiceAdapterCreator,
});
}
})


client.login(process.env.token);
duck
duck10mo ago
so then import joinVoiceChannel from @discordjs/voice
Maxzie
Maxzie10mo ago
I’ll try Wait a second, how do I import it again?
Danial
Danial10mo ago
Importing/requring something is basic JavaScript, do you know much of JavaScript?
Maxzie
Maxzie10mo ago
i only know html javascript and i forgot most of it 💀
Danial
Danial10mo ago
Then I recommend you check out #resources to brush up on your JavaScript fundamentals
Maxzie
Maxzie10mo ago
Thanks
Danial
Danial10mo ago
Of course
Maxzie
Maxzie10mo ago
I'll try it tomorrow because I have to go soon
Danial
Danial10mo ago
Sounds good