I was using a tutorial on youtube to make a music Discord bot with javascript and I run into this problems with the guilds, i have already changed them for the new guild-names as seen on the source code, but it did not seem to work although I am using discord.js v14
This is the error message
PS C:UsersmatiaDesktopbot_de_discord> node index.js
C:UsersmatiaDesktopbot_de_discordnode_modulesdiscord-playerdistPlayer.js:51
throw new PlayerError_1.PlayerError('client is missing "GuildVoiceStates" intent');
^
PlayerError: [PlayerError] client is missing "GuildVoiceStates" intent
at new PlayerError (C:UsersmatiaDesktopbot_de_discordnode_modulesdiscord-playerdistStructuresPlayerError.js:28:15)
at new Player (C:UsersmatiaDesktopbot_de_discordnode_modulesdiscord-playerdistPlayer.js:51:19)
at Object.<anonymous> (C:UsersmatiaDesktopbot_de_discordindex.js:28:17)
at Module._compile (node:internal/modules/cjs/loader:1155:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
at Module.load (node:internal/modules/cjs/loader:1033:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47 {
createdAt: 2022-10-22T20:46:33.101Z,
statusCode: 'PlayerError'
}
And this is the source code
const Discord = require("discord.js")
const dotenv = require("dotenv")
const { REST } = require("@discordjs/rest")
const { Routes } = require("discord-api-types/v9")
const fs = require("fs")
const { Player } = require("discord-player")
dotenv.config()
const TOKEN = process.env.TOKEN
const LOAD_SLASH = process.argv[2] == "load"
const CLIENT_ID = "1033422580654280774"
const GUILD_ID = "699272174736900117"
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
]
})
client.slashcommands = new Discord.Collection()
client.player = new Player(client, {
ytdlOptions: {
quality: "highestaudio",
highWaterMark: 1 << 25
}
})
let commands = []
const slashFiles = fs.readdirSync("./slash").filter(file => file.endsWith(".js"))
for (const file of slashFiles){
const slashcmd = require(`./slash/${file}`)
client.slashcommands.set(slashcmd.data.name, slashcmd)
if (LOAD_SLASH) commands.push(slashcmd.data.toJSON())
}
if (LOAD_SLASH) {
const rest = new REST({ version: "9" }).setToken(TOKEN)
console.log("Deploying slash commands")
rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), {body: commands})
.then(() => {
console.log("Successfully loaded")
process.exit(0)
})
.catch((err) => {
if (err){
console.log(err)
process.exit(1)
}
})
}
else {
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`)
})
client.on("interactionCreate", (interaction) => {
async function handleCommand() {
if (!interaction.isCommand()) return
const slashcmd = client.slashcommands.get(interaction.commandName)
if (!slashcmd) interaction.reply("Not a valid slash command")
await interaction.deferReply()
await slashcmd.run({ client, interaction })
}
handleCommand()
})
client.login(TOKEN)
}