Repository navigation
Expand file tree
/
Copy pathbotEmote.js
More file actions
89 lines (77 loc) · 2.73 KB
/
Copy pathbotEmote.js
File metadata and controls
89 lines (77 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { SlashCommandBuilder } from "discord.js";
import { fetchMessage, interactionReply } from "ewilib";
import { PERSONALITY } from "../classes/personality.js";
import { isAdmin } from "../helpers/utils.js";
const command = new SlashCommandBuilder()
.setName(PERSONALITY.getPersonality().botEmote.name)
.setDescription(PERSONALITY.getPersonality().botEmote.description)
.setDefaultMemberPermissions(0x0000010000000000)
.addStringOption((option) =>
option
.setName(PERSONALITY.getPersonality().botEmote.messageOption.name)
.setDescription(
PERSONALITY.getPersonality().botEmote.messageOption.description,
)
.setRequired(true)
.setMinLength(1),
)
.addStringOption((option) =>
option
.setName(PERSONALITY.getPersonality().botEmote.emoteOption.name)
.setDescription(
PERSONALITY.getPersonality().botEmote.emoteOption.description,
)
.setRequired(true)
.setAutocomplete(true),
);
const action = async (interaction) => {
const perso = PERSONALITY.getPersonality().botEmote;
if (!isAdmin(interaction.user.id)) {
interactionReply(interaction, perso.errorNotAdmin);
console.log(`${interaction.user.id} tried to use /reaction`);
return;
}
//get options
const options = interaction.options;
const messageId = options.getString(perso.messageOption.name);
const emoteId = options.getString(perso.emoteOption.name);
//fetch message
let message;
try {
message = await fetchMessage(interaction.channel.messages, messageId);
} catch (e) {
console.log("/reaction error - message not found", e);
interactionReply(interaction, perso.errorMessageNotFound);
return;
}
//get emote
const emote = interaction.guild.emojis.cache.get(emoteId);
//react
const result = await message.react(emote);
if (result) interactionReply(interaction, perso.react);
else interactionReply(interaction, perso.errorNotReact);
};
const autocomplete = (interaction) => {
const value = interaction.options.getFocused(); //get value which is currently user edited
const focusedValue = value.toLowerCase();
const emotesCache = interaction.guild.emojis.cache;
//build list
const emotes = emotesCache.map((cur) => {
return { name: cur.name.toLowerCase(), value: cur.id };
});
const filtered = emotes.filter((cur) => cur.name.startsWith(focusedValue)); //filter to corresponding emotes names
const sliced = filtered.length > 24 ? filtered.slice(0, 24) : filtered;
interaction.respond(sliced);
};
const botEmote = {
command,
action,
autocomplete,
help: (interaction) => {
const perso = PERSONALITY.getPersonality().botEmote;
interactionReply(interaction, perso.help);
},
admin: true,
sentinelle: false,
};
export default botEmote;