feat: rory command!!!
This commit is contained in:
parent
e1daf40512
commit
a45a7e3580
3 changed files with 57 additions and 0 deletions
|
@ -49,6 +49,9 @@ export const reuploadCommands = async () => {
|
|||
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
|
||||
.setDMPermission(false),
|
||||
new SlashCommandBuilder().setName('joke').setDescription("it's a joke"),
|
||||
new SlashCommandBuilder().setName('rory').setDescription("Gets a Rory photo!")
|
||||
.addStringOption((option) =>
|
||||
option.setName("id").setDescription("specify a Rory ID").setRequired(false)),
|
||||
].map((command) => command.toJSON());
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN!);
|
||||
|
|
51
src/commands/rory.ts
Normal file
51
src/commands/rory.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import type { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
|
||||
export interface RoryResponse {
|
||||
/**
|
||||
* The ID of this Rory
|
||||
*/
|
||||
id: number;
|
||||
/**
|
||||
* The URL to the image of this Rory
|
||||
*/
|
||||
url: string;
|
||||
/**
|
||||
* When error :(
|
||||
*/
|
||||
error: string | undefined;
|
||||
}
|
||||
|
||||
export const roryCommand = async (
|
||||
i: ChatInputCommandInteraction<CacheType>
|
||||
) => {
|
||||
await i.deferReply();
|
||||
|
||||
const { value: id } = i.options.get('id') ?? { value: '' };
|
||||
|
||||
const rory: RoryResponse = await fetch(`https://rory.cat/purr/${id}`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
}).then((r) => r.json());
|
||||
|
||||
if (rory.error) {
|
||||
await i.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder().setTitle('Error!').setDescription(rory.error),
|
||||
],
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await i.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setTitle('Rory :3')
|
||||
.setURL(`https://rory.cat/id/${rory.id}`)
|
||||
.setImage(rory.url)
|
||||
.setFooter({
|
||||
text: `ID ${rory.id}`,
|
||||
}),
|
||||
],
|
||||
});
|
||||
};
|
|
@ -16,6 +16,7 @@ import { starsCommand } from './commands/stars';
|
|||
import { modrinthCommand } from './commands/modrinth';
|
||||
import { tagsCommand } from './commands/tags';
|
||||
import { jokeCommand } from './commands/joke';
|
||||
import { roryCommand } from "./commands/rory";
|
||||
|
||||
import random from 'just-random';
|
||||
import { green, bold, yellow, cyan } from 'kleur/colors';
|
||||
|
@ -120,6 +121,8 @@ client.on('interactionCreate', async (interaction) => {
|
|||
await tagsCommand(interaction);
|
||||
} else if (commandName === 'joke') {
|
||||
await jokeCommand(interaction);
|
||||
} else if (commandName === "rory") {
|
||||
await roryCommand(interaction);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue