add play command as a simple copy paste from guides
This commit is contained in:
parent
5feb1b2742
commit
4e7645c0e1
3 changed files with 102 additions and 10 deletions
|
@ -1,23 +1,108 @@
|
|||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { ChatInputCommandInteraction, Client } from "discord.js";
|
||||
import {
|
||||
ChatInputCommandInteraction,
|
||||
Client,
|
||||
GuildResolvable,
|
||||
VoiceBasedChannel,
|
||||
} from "discord.js";
|
||||
import { getLocalizations } from "../../utils/locales";
|
||||
import { getFilename } from "../../utils/misc";
|
||||
import { Metadata } from "../../modules/metadata";
|
||||
|
||||
export default {
|
||||
scope: () => [],
|
||||
|
||||
data: (client: Client) => {
|
||||
const filename = getFilename(__filename);
|
||||
return new SlashCommandBuilder()
|
||||
const loc_default = client.locales.get(client.config.default_lang);
|
||||
if (!loc_default) {
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
new SlashCommandBuilder()
|
||||
.setName(filename.toLowerCase())
|
||||
.setDescription(
|
||||
client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? ""
|
||||
)
|
||||
.setDescription(loc_default.get(`c_${filename}_desc`) ?? "")
|
||||
.setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true))
|
||||
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`));
|
||||
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`))
|
||||
|
||||
// Command option
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName(loc_default.get(`c_${filename}_opt1_name`)?.toLowerCase() ?? "")
|
||||
.setDescription(loc_default.get(`c_${filename}_opt1_desc`) ?? "")
|
||||
.setNameLocalizations(getLocalizations(client, `c_${filename}_opt1_name`, true))
|
||||
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_opt1_desc`))
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
interaction: async (interaction: ChatInputCommandInteraction, client: Client) => {
|
||||
interaction.reply("coucou");
|
||||
const loc_default = client.locales.get(client.config.default_lang);
|
||||
const filename = getFilename(__filename);
|
||||
|
||||
const member = client.guilds.cache
|
||||
.get(interaction.guildId ?? "")
|
||||
?.members.cache.get(interaction.member?.user.id ?? "");
|
||||
|
||||
if (!member?.voice.channelId) {
|
||||
return await interaction.reply({
|
||||
content: "Tu n'es dans aucun salon vocal.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
interaction.guild?.members.me?.voice.channelId &&
|
||||
member.voice.channelId !== interaction.guild.members.me.voice.channelId
|
||||
) {
|
||||
return await interaction.reply({
|
||||
content: "Je suis déjà en vocal.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
const query =
|
||||
interaction.options.getString(loc_default?.get(`c_${filename}_opt1_name`) as string) ?? "";
|
||||
|
||||
const queue = client.player.createQueue(interaction.guild as GuildResolvable, {
|
||||
metadata: {
|
||||
channel: interaction.channel,
|
||||
},
|
||||
});
|
||||
|
||||
// Verify vc connection
|
||||
try {
|
||||
if (!queue.connection) await queue.connect(member.voice.channel as VoiceBasedChannel);
|
||||
} catch {
|
||||
queue.destroy();
|
||||
return await interaction.reply({
|
||||
content: "Impossible de rejoindre le salon vocal.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
await interaction.deferReply();
|
||||
const track = await client.player
|
||||
.search(query, {
|
||||
requestedBy: interaction.user,
|
||||
})
|
||||
.then((x) => x.tracks[0]);
|
||||
|
||||
if (!track) {
|
||||
return await interaction.followUp({ content: `❌ | \`${query}\` introuvable.` });
|
||||
}
|
||||
|
||||
// TMP
|
||||
client.player.on("error", () => console.log("error"));
|
||||
client.player.on("connectionError", () => console.log("error"));
|
||||
client.player.on("trackStart", (q, t) =>
|
||||
(q.metadata as Metadata).channel?.send(`🎶 | Joue \`${t.title}\`.`)
|
||||
);
|
||||
//
|
||||
|
||||
await queue.play(track);
|
||||
|
||||
return await interaction.followUp({ content: `⏱️ | Chargement de \`${track.title}\`.` });
|
||||
},
|
||||
};
|
||||
|
|
|
@ -79,5 +79,7 @@
|
|||
"c_reminder18": "Pas de message",
|
||||
|
||||
"c_play_name": "play",
|
||||
"c_play_desc": "Joue une chanson/playlist"
|
||||
"c_play_desc": "Joue une chanson/playlist",
|
||||
"c_play_opt1_name": "requête",
|
||||
"c_play_opt1_desc": "Ce que vous voulez écouter"
|
||||
}
|
||||
|
|
5
src/modules/metadata.ts
Normal file
5
src/modules/metadata.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { TextBasedChannel } from "discord.js";
|
||||
|
||||
export type Metadata = {
|
||||
channel: TextBasedChannel | null;
|
||||
};
|
Loading…
Reference in a new issue