/[sudobot]/trunk/src/commands/information/EmojiCommand.ts
ViewVC logotype

Contents of /trunk/src/commands/information/EmojiCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 314 - (show annotations)
Mon Jul 29 17:29:30 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 4560 byte(s)
fix: emoji command not working (#62)
1 import { CommandInteraction, Emoji, Message, Util } from 'discord.js';
2 import BaseCommand from '../../utils/structures/BaseCommand';
3 import DiscordClient from '../../client/Client';
4 import CommandOptions from '../../types/CommandOptions';
5 import InteractionOptions from '../../types/InteractionOptions';
6 import axios from 'axios';
7 import path from 'path';
8 import { deleteFile, download, timeSince } from '../../utils/util';
9 import MessageEmbed from '../../client/MessageEmbed';
10
11 export default class EmojiCommand extends BaseCommand {
12 supportsInteractions: boolean = true;
13
14 constructor() {
15 super('emoji', 'information', []);
16 }
17
18 async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
19 if (!options.isInteraction && options.args[0] === undefined) {
20 await msg.reply({
21 embeds: [
22 new MessageEmbed()
23 .setColor('#f14a60')
24 .setDescription(':x: This command requires at least one argument.')
25 ]
26 });
27
28 return;
29 }
30
31 let emojiString: string;
32
33 if (options.isInteraction) {
34 emojiString = await <string> options.options.getString('emoji');
35 }
36 else {
37 emojiString = options.args[0];
38 }
39
40 const emojiSubString = emojiString.startsWith('<:') && emojiString.endsWith('>') ? emojiString.substring(2, emojiString.length - 1) : emojiString;
41
42 let emoji = await client.emojis.cache.find(e => e.name === emojiSubString || e.identifier === emojiSubString || e.id === emojiSubString);
43
44 if (!emoji) {
45 if ((emojiString.startsWith('<:') && emojiString.endsWith('>')) || /\d+/g.test(emojiString)) {
46 let parsedEmoji = emojiString.startsWith('<:') && emojiString.endsWith('>') ? Util.parseEmoji(emojiString) : { animated: undefined, id: emojiString, name: undefined };
47
48 if (!parsedEmoji) {
49 await msg.reply({
50 embeds: [
51 new MessageEmbed()
52 .setColor('#f14a60')
53 .setDescription('Invalid emoji!')
54 ]
55 });
56
57 return;
58 }
59
60 await msg.reply({
61 embeds: [
62 new MessageEmbed()
63 .setAuthor({
64 name: parsedEmoji.name ?? "Unknown Emoji",
65 iconURL: `https://cdn.discordapp.com/emojis/${parsedEmoji.id}`,
66 })
67 .setFields({
68 name: "Animated",
69 value: parsedEmoji.animated !== undefined ? parsedEmoji.animated ? 'Yes' : 'No' : "*The system could not load enough information*",
70 }, {
71 name: "Download",
72 value: `[Click Here](https://cdn.discordapp.com/emojis/${parsedEmoji.id})`
73 })
74 .setThumbnail(`https://cdn.discordapp.com/emojis/${parsedEmoji.id}`)
75 .setFooter({
76 text: `ID: ${parsedEmoji.id}`
77 })
78 ]
79 });
80 }
81 else {
82 await msg.reply({
83 embeds: [
84 new MessageEmbed()
85 .setColor('#f14a60')
86 .setDescription('No emoji found or not a guild based emoji!')
87 ]
88 });
89 }
90
91 return;
92 }
93
94 await msg.reply({
95 embeds: [
96 new MessageEmbed()
97 .setAuthor({
98 name: emoji.guild.name,
99 iconURL: emoji.guild.iconURL()!,
100 })
101 .setTitle(emoji.name ?? 'Emoji Information')
102 .addField('Name', emoji.name ?? '*No name set*')
103 .addField('Identifier', emoji.identifier ?? '*No identifier set*')
104 .addField('Available', emoji.available ? 'Yes' : 'No')
105 .addField('Created', timeSince(emoji.createdAt.getTime()))
106 .addField('Download', `[Click here](${emoji.url})`)
107 .setThumbnail(emoji.url)
108 .setFooter({
109 text: `ID: ${emoji.id}`
110 })
111 ]
112 });
113 }
114 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26