Added first anime command

This commit is contained in:
2024-02-15 21:42:43 +01:00
parent 1ac334a323
commit 0747287fd6
2 changed files with 101 additions and 0 deletions

49
src/commands/anime.ts Normal file
View File

@@ -0,0 +1,49 @@
import { PermissionFlagsBits, SlashCommandBuilder } from "discord.js"
import { Command } from "interfaces"
import search from "./anime/search"
import { devMessage, embedColor } from "config/options"
export = {
name: "anime",
description: "Anime subcommands",
public: true,
dev: true,
subcommands: true,
data: new SlashCommandBuilder()
.setName("anime")
.setDescription("Anime subcommands")
.addSubcommand(subcommand =>
subcommand
.setName("search")
.setDescription("Search for an anime")
.addStringOption(option =>
option
.setName("query")
.setDescription("The anime to search for")
.setRequired(true)
)
)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.setDMPermission(false),
async execute(interaction) {
const subcommand = interaction.options.getSubcommand()
if (subcommand === "search") {
search(interaction)
return
}
await interaction.reply({
embeds: [{
description: "This command is currently under development",
color: embedColor,
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
}
}]
})
}
} as Command

View File

@@ -0,0 +1,52 @@
import { ChatInputCommandInteraction } from "discord.js"
import { anilist } from "anilist"
import { embedColor } from "config/options"
export default async function search(interaction: ChatInputCommandInteraction) {
await interaction.deferReply()
const query = interaction.options.getString("query")!
const data = anilist.query.media()
.arguments({ search: query, type: "ANIME" })
.withTitles("english", "romaji")
.withDescription()
.withCoverImage("medium")
.withDuration()
.withGenres()
.withAverageScore()
.withMeanScore()
const anime = await data.fetch()
if (!anime) {
await interaction.editReply({
embeds: [{
description: "No anime found",
color: embedColor
}]
})
}
const romaji = anime.title?.romaji || "Romaji not available"
const english = anime.title?.english || "English not available"
const animeDescription = anime.description?.replaceAll("<br>", "\n").slice(0, 256) + "..." || "No description available"
await interaction.editReply({
embeds: [{
title: romaji + " | " + english,
description: `
**Description:** ${animeDescription}
**Genres:** ${anime.genres.join(", ")}
**Avg. Score:** ${anime.averageScore || "No score available"}
**Mean Score:** ${anime.meanScore || "No score available"}
`,
color: embedColor,
thumbnail: {
url: anime.coverImage?.medium || ""
},
footer: {
text: anime.duration?.toString() + " minute episodes" || "No duration available"
}
}]
})
}