/
clearReactions.js
40 lines (34 loc) · 1.15 KB
/
clearReactions.js
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
module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);
const [channelID, messageID, emoji = "all"] = data.inside.splits;
const channel = await d.util.getChannel(d, channelID);
if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside });
const message = await d.util.getMessage(channel, messageID);
if (!message) return d.aoiError.fnError(d, "message", { inside: data.inside });
if (emoji === "all") {
message.reactions.removeAll().catch((err) => {
d.aoiError.fnError(
d,
"custom",
{},
"Failed To Remove All Reactions With Reason: " + err,
);
});
return {
code: d.util.setCode(data),
};
} else {
message.reactions.cache
.find(
(x) =>
x.emoji.toString() === emoji ||
x.emoji.name.toLowerCase() === emoji.toLowerCase() ||
x.emoji.id === emoji,
)
?.remove();
}
return {
code: d.util.setCode(data),
};
};