b68/packages/bot/src/commands/slash/shuffle.ts

49 lines
1.5 KiB
TypeScript

import { SlashCommandBuilder } from 'discord.js'
import { bot } from '../../index'
import { i18n } from '../../utils/i18n'
import { canModifyQueue } from '../../utils/queue'
import { SlashCommand } from '../../sturctures/command'
export const command: SlashCommand = {
slashData: new SlashCommandBuilder()
.setName('shuffle')
.setDescription(i18n.__('shuffle.description')),
run: (itd) => {
const { interaction }: any = itd
const queue = bot.queues.get(interaction.guild!.id)
const guildMemer = interaction.guild!.members.cache.get(
interaction.user.id
)
if (!queue)
return interaction
.reply({
content: i18n.__('shuffle.errorNotQueue'),
ephemeral: true,
})
.catch(console.error)
if (!guildMemer || !canModifyQueue(guildMemer))
return i18n.__('common.errorNotChannel')
const songs = queue.songs
for (let i = songs.length - 1; i > 1; i--) {
const j = 1 + Math.floor(Math.random() * i)
;[songs[i], songs[j]] = [songs[j], songs[i]]
}
queue.songs = songs
const content = {
content: i18n.__mf('shuffle.result', {
author: interaction.user.id,
}),
}
if (interaction.replied)
interaction.followUp(content).catch(console.error)
else interaction.reply(content).catch(console.error)
},
}