Tokyo?
DIAdiscord.js - Imagine an app
•Created by Tokyo? on 9/27/2023 in #djs-voice
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.`)
}
},
};
// 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],
});
}
4 replies