-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
113 lines (92 loc) · 3.65 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { dirname, importx } from "@discordx/importer";
import type { Interaction, Message } from "discord.js";
import { IntentsBitField, ActivityType } from "discord.js"; // Import ActivityType
import { Client } from "discordx";
console.log(`$$\\ $$\\ $$\\ $$\\
$$$\\ $$$ | \\__| $$ |
$$$$\\ $$$$ | $$$$$\\\\ $$$$$\\\\ $$\\ $$$$$$$\\ $$$$$\\\\ $$$$$\\\\ $$$$$$$ |
$$\\$$\\$$ $$ | \\____$$\\ $$ __$$\\ $$ |$$ _____|$$ __$$\\ $$ __$$\\ $$ __$$ |
$$ \\$$$ $$ | $$$$$$$ |$$ / $$ |$$ |$$ / $$ / $$ |$$ | \\__|$$ / $$ |
$$ |\\$ /$$ |$$ __$$ |$$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |
$$ | \\_/ $$ |\\$$$$$$$ |\\$$$$$$$ |$$ |\\$$$$$$$\\ \\$$$$$$ |$$ | \\$$$$$$$ |
\\__| \\__| \\_______| \\____$$ |\\__| \\_______| \\______/ \\__| \\_______|
$$\\ $$ |
\\$$$$$$ |
\\______/
Always free, Always open source`);
export const bot = new Client({
// To use only guild command
// botGuilds: [(client) => client.guilds.cache.map((guild) => guild.id)],
// Discord intents
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMessageReactions,
IntentsBitField.Flags.GuildVoiceStates,
],
// Debug logs are disabled in silent mode
silent: false,
// Configuration for @SimpleCommand
simpleCommand: {
prefix: "!",
},
});
bot.once("ready", async () => {
// Make sure all guilds are cached
// await bot.guilds.fetch();
// Synchronize applications commands with Discord
void bot.initApplicationCommands();
// Set the status of the bot
if (bot.user) {
bot.user.setActivity('How to cast spells (FULL TUTORIAL)', { type: ActivityType.Watching });
}
// To clear all guild commands, uncomment this line,
// This is useful when moving from guild commands to global commands
// It must only be executed once
//
// await bot.clearApplicationCommands(
// ...bot.guilds.cache.map((g) => g.id)
// );
console.log("Bot started");
});
bot.on("interactionCreate", async (interaction: Interaction) => {
try {
await bot.executeInteraction(interaction);
} catch (error) {
const err = error as { code?: number };
if (err.code === 10062) {
console.warn("Unknown interaction detected, possibly expired:", err);
} else {
console.error("Error handling interaction:", err);
}
}
});
bot.on("messageCreate", async (message: Message) => {
try {
await bot.executeCommand(message);
} catch (error) {
console.error("Error handling message:", error);
}
});
async function run() {
// The following syntax should be used in the commonjs environment
//
// await importx(__dirname + "/{events,commands}/**/*.{ts,js}");
// The following syntax should be used in the ECMAScript environment
await importx(`${dirname(import.meta.url)}/{events,commands}/**/*.{ts,js}`);
// Let's start the bot
if (!process.env.BOT_TOKEN) {
throw Error("Could not find BOT_TOKEN in your environment");
}
// Log in with your bot token
await bot.login(process.env.BOT_TOKEN);
}
// Global error handling
process.on("unhandledRejection", (reason, promise) => {
console.error("Unhandled Rejection at:", promise, "reason:", reason);
});
process.on("uncaughtException", (error) => {
console.error("Uncaught Exception:", error);
});
void run();