forked from LAION-AI/Open-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.ts
78 lines (73 loc) · 2.25 KB
/
messages.ts
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
import { Events } from "discord.js";
const msgType = {
type: "message",
load: async (msg) => {
await msg.react("<a:loading:1051419341914132554>");
try {
await msg.channel.sendTyping();
} catch (err) {}
},
reply: async (msg, content) => {
try {
const userReactions = msg.reactions.cache.filter((reaction) =>
reaction.users.cache.has(process.env.CLIENT_ID)
);
try {
for (const reaction of userReactions.values()) {
reaction.users.remove(process.env.CLIENT_ID);
}
} catch (error) {
console.error("Failed to remove reactions:", error);
}
return await msg.reply(content);
} catch (err) {
console.log(err);
}
},
};
export default {
name: Events.MessageCreate,
once: false,
async execute(message, client) {
if (message.mentions.has(client.user) && !message.author.bot) {
var content = message.content;
// if is ping by @everyone or @here or @role ignore
if (
message.content.includes("@everyone") ||
message.content.includes("@here") ||
message.content.includes("<@&")
)
return;
if (message.content.includes(`<@${client.user.id}>`)) {
if (!message.content.startsWith(`<@${client.user.id}>`)) return;
content = message.content.split(`<@${client.user.id}> `)[1];
}
var commandName = content;
var commands = await client.commands.toJSON();
if (!commandName) commandName = "help";
var command = client.commands.get(commandName);
var options: any = {};
message.user = message.author;
if (!command) {
commandName = "chat";
command = client.commands.get(commandName);
}
if (commandName == "chat" || content.startsWith("chat ")) {
options.message = content.replace("chat ", "");
}
if (command.disablePing) return;
var guildId;
if (message.guild) guildId = message.guild.id;
try {
await command.execute(message, client, commands, msgType, options);
} catch (error) {
try {
await message.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
} catch (err) {}
}
}
},
};