diff --git a/source/commands/me/vote.js b/source/commands/me/vote.js index b7637b33..b5ddb9a6 100644 --- a/source/commands/me/vote.js +++ b/source/commands/me/vote.js @@ -5,47 +5,47 @@ const { ActionRowBuilder, ButtonBuilder, ButtonStyle, + resolveColor, } = require('discord.js') module.exports = { permissions: [PermissionFlagsBits.SendMessages], data: new SlashCommandBuilder() .setName('vote') - .setDescription('Vote for this bot on Top.gg.') + .setDescription('Vote for me on top.gg') .setDescriptionLocalizations({ - th: 'โหวตคะแนนให้บอทนี้บน top.gg', + th: 'โหวตคะแนนให้ฉันบน top.gg', }) .setDefaultMemberPermissions() .setDMPermission(true), async execute(interaction) { await interaction.deferReply() - const clientAvatar = interaction.client.user.avatarURL() - const clientUsername = interaction.client.user.username - const clientUserID = interaction.client.user.id - - const topName = 'top.gg' - const topColor = '#FF3366' - const topURL = 'https://top.gg' - const topFavicon = `${topURL}/favicon.png` - const topBotLink = `${topURL}/bot/${clientUserID}` - const response = await fetch(`${topURL}/api/bots/${clientUserID}`, { + const response = await fetch(`https://top.gg/api/bots/${clientUserID}`, { headers: { Authorization: interaction.client.configs.top_gg_token, }, }) - if (response.status !== 200) + if (response.status === 404) return await interaction.editReply( interaction.client.i18n.t('commands.vote.not_found') ) + if (response.status === 401) + return await interaction.editReply( + interaction.client.i18n.t('commands.vote.unauthorized') + ) + if (response.status !== 200) + return await interaction.editReply( + interaction.client.i18n.t('commands.vote.error') + ) const data = await response.json() - const date = new Date(data.date) + const date = data.date const invite = data.invite const point = data.points const shortDescription = data.shortdesc - const tags = data.tags.join(', ') + const tags = data.tags const voteRow = new ActionRowBuilder().addComponents( new ButtonBuilder() @@ -53,31 +53,41 @@ module.exports = { .setLabel(interaction.client.i18n.t('commands.vote.invite')) .setStyle(ButtonStyle.Link), new ButtonBuilder() - .setURL(`${topBotLink}/vote`) + .setURL(`https://top.gg/bot/${clientUserID}/vote`) .setLabel(interaction.client.i18n.t('commands.vote.vote')) .setStyle(ButtonStyle.Link) ) + + const clientAvatar = interaction.client.user.avatarURL() + const clientUsername = interaction.client.user.username + const clientUserID = interaction.client.user.id const voteEmbed = new EmbedBuilder() .setTitle(clientUsername) - .setURL(topBotLink) + .setURL(`https://top.gg/bot/${clientUserID}`) .setDescription(`\`\`\`${shortDescription}\`\`\``) .setFields( { - name: interaction.client.i18n.t('commands.vote.votes'), - value: point.toString(), + name: interaction.client.i18n.t('commands.vote.rate'), + value: String(point), inline: false, }, { name: interaction.client.i18n.t('commands.vote.tags'), - value: tags, + value: tags.join(', '), inline: false, } ) .setThumbnail(clientAvatar) - .setColor(topColor) - .setTimestamp(date) - .setFooter({ text: interaction.client.i18n.t('commands.vote.added') }) - .setAuthor({ name: topName, iconURL: topFavicon, url: topURL }) + .setColor(resolveColor('#FF3366')) + .setTimestamp(new Date(date)) + .setFooter({ + text: interaction.client.i18n.t('commands.vote.added'), + }) + .setAuthor({ + name: 'top.gg', + iconURL: `https://top.gg/favicon.png`, + url: 'https://top.gg', + }) await interaction.editReply({ embeds: [voteEmbed],