Answer the question
In order to leave comments, you need to log in
The voice of the bot does not work. (Music bot) Why?
There are no problems with any commands. The fact is that when I enter the name of the song, the bot finds it, everything is clear, and when it comes to me in the voice, you can see by the green edging that it pronounces some sounds in theory, but nothing like that is heard. Here is the code for each:
const { Player } = require("discord-player");
// Create a new Player (you don't need any API Key)
const player = new Player(client);
// To easily access the player
client.player = player;
// add the trackStart event so when a song will be played this message will be sent
client.player.on('trackStart', (message, track) => message.channel.send(`Now playing ${track.title}...`))
client.on("ready", () => {
console.log("I'm ready !");
});
client.on("message", async (message) => {
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
// !play Despacito
// will play "Despacito" in the member voice channel
if(command === "play"){
client.player.play(message, args[0], message.member.user);
// as we registered the event above, no need to send a success message here
}
});
client.player
// Send a message when a track starts
.on('trackStart', (message, track) => message.channel.send(`Now playing ${track.title}...`))
// Send a message when something is added to the queue
.on('trackAdd', (message, track) => message.channel.send(`${track.title} has been added to the queue!`))
.on('playlistAdd', (message, playlist) => message.channel.send(`${playlist.title} has been added to the queue (${playlist.items.length} songs)!`))
// Send messages to format search results
.on('searchResults', (message, query, tracks) => {
const embed = new Discord.MessageEmbed()
.setAuthor(`Here are your search results for ${query}!`)
.setDescription(tracks.map((t, i) => `${i}. ${t.title}`))
.setFooter('Send the number of the song you want to play!')
message.channel.send(embed);
})
.on('searchInvalidResponse', (message, query, tracks, content, collector) => message.channel.send(`You must send a valid number between 1 and ${tracks.length}!`))
.on('searchCancel', (message, query, tracks) => message.channel.send('You did not provide a valid response... Please send the command again!'))
.on('noResults', (message, query) => message.channel.send(`No results found on YouTube for ${query}!`))
// Send a message when the music is stopped
.on('queueEnd', (message, queue) => message.channel.send('Music stopped as there is no more music in the queue!'))
.on('channelEmpty', (message, queue) => message.channel.send('Music stopped as there is no more member in the voice channel!'))
.on('botDisconnect', (message, queue) => message.channel.send('Music stopped as I have been disconnected from the channel!'))
// Error handling
.on('error', (error, message) => {
switch(error){
case 'NotPlaying':
message.channel.send('There is no music being played on this server!')
break;
case 'NotConnected':
message.channel.send('You are not connected in any voice channel!')
break;
case 'UnableToJoin':
message.channel.send('I am not able to join your voice channel, please check my permissions!')
break;
default:
message.channel.send(`Something went wrong... Error: ${error}`)
}
})
Answer the question
In order to leave comments, you need to log in
Found a solution. Another trouble arose, the bot almost spamming with messages .. roughly speaking:
The song "song name" is
playing The song "song name" is
playing The song "song name" is playing The song "song name" is
playing
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question