Skip to content

Commit

Permalink
🫧 Increase efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
Maseshi committed May 20, 2024
1 parent 4bc12ce commit b434f28
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions source/commands/me/vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,89 @@ 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()
.setURL(invite)
.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],
Expand Down

0 comments on commit b434f28

Please sign in to comment.