Find music but don't play

import { EmbedBuilder } from 'discord.js';
import { joinVoiceChannel } from '@discordjs/voice';
import { Default } from '../../../../botconfig.json';
const { formatDuration } = require('discord-player-plus')

module.exports = {
name: "play",
aliases: ["p"],
description: "Permet de jouer une musique à partir d'un titre.",
usage: "<title>",
permission: "NoPermission",
OwnerOnly: false,

async execute(client: any, message: any, args: any, playerManager: any){

const member = message.guild.members.cache.get(`${message.author.id}`);

if (member.voice.channel) {
const voiceChannel = member.voice.channel
joinVoiceChannel({
channelId: member.voice.channel.id,
guildId: member.guild.id,
adapterCreator: member.guild.voiceAdapterCreator,
})

const player = playerManager.get(`${message.guild.id}`);
const searchResult = await player.search(`${args}`);
if (searchResult?.tracks.length) {
await player.play({
channel: voiceChannel,
tracks: searchResult.tracks[0],
});
} else {
message.reply("Musique inconnue.")
return
}

const dur = formatDuration(searchResult.tracks[0].duration)

const Embed = new EmbedBuilder()
.setAuthor({name: `${searchResult.tracks[0].artist}`})
.setDescription(`**Joue** \`\`${searchResult.tracks[0].title}\`\``)
.setImage(searchResult.tracks[0].thumbnailUrl)
.setFooter({text: `${dur}`})
.setColor(Default.EmbedColor)

message.channel.send({embeds: [Embed]})
} else {
message.reply(`Aucun salon vocal.`)
}

},
};
import { EmbedBuilder } from 'discord.js';
import { joinVoiceChannel } from '@discordjs/voice';
import { Default } from '../../../../botconfig.json';
const { formatDuration } = require('discord-player-plus')

module.exports = {
name: "play",
aliases: ["p"],
description: "Permet de jouer une musique à partir d'un titre.",
usage: "<title>",
permission: "NoPermission",
OwnerOnly: false,

async execute(client: any, message: any, args: any, playerManager: any){

const member = message.guild.members.cache.get(`${message.author.id}`);

if (member.voice.channel) {
const voiceChannel = member.voice.channel
joinVoiceChannel({
channelId: member.voice.channel.id,
guildId: member.guild.id,
adapterCreator: member.guild.voiceAdapterCreator,
})

const player = playerManager.get(`${message.guild.id}`);
const searchResult = await player.search(`${args}`);
if (searchResult?.tracks.length) {
await player.play({
channel: voiceChannel,
tracks: searchResult.tracks[0],
});
} else {
message.reply("Musique inconnue.")
return
}

const dur = formatDuration(searchResult.tracks[0].duration)

const Embed = new EmbedBuilder()
.setAuthor({name: `${searchResult.tracks[0].artist}`})
.setDescription(`**Joue** \`\`${searchResult.tracks[0].title}\`\``)
.setImage(searchResult.tracks[0].thumbnailUrl)
.setFooter({text: `${dur}`})
.setColor(Default.EmbedColor)

message.channel.send({embeds: [Embed]})
} else {
message.reply(`Aucun salon vocal.`)
}

},
};
that's succefully find music but don't play idk why and the exemple in the doc is:
// get your voice channel here, e.g. from a slash command
const voiceChannel;

const searchResult = await player.search("Luis Fonsi - Despacito");
if (searchResult?.tracks.length) {
await player.play({
channel: voiceChannel,
// play first matched song for Despacito
tracks: searchResult.tracks[0],
});
}
// get your voice channel here, e.g. from a slash command
const voiceChannel;

const searchResult = await player.search("Luis Fonsi - Despacito");
if (searchResult?.tracks.length) {
await player.play({
channel: voiceChannel,
// play first matched song for Despacito
tracks: searchResult.tracks[0],
});
}
3 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! - Marked as resolved by staff
treble/luna
treble/luna15mo ago
discord player plus is agains tos, we do not support tos violations
Tokyo?
Tokyo?OP14mo ago
AH okk sry i didn't know
Want results from more Discord servers?
Add your server