Skip to content

Updated to Discord.js v14 #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotenv_sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ TOKEN=ENTER_BOT_TOKEN_HERE
# The bot's application id, get it from https://discord.com/developers/applications -> your bot -> General Information -> Application ID
APPLICATIONID=1234567890123456789

# The ID of the guild on which the commands will be registered to (if the commands are being registered on a guild)
# The ID of the guild (server) on which the commands will be registered to (if the commands are being registered on a guild)
GUILDID=1234567890123456789
6,298 changes: 1,276 additions & 5,022 deletions package-lock.json

Large diffs are not rendered by default.

41 changes: 18 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "tph_docs_bot",
"version": "1.0.0",
"description": "A Discord bot to display documentation ",
"description": "A Discord bot to display documentation.",
"main": "dist/bot.js",
"type": "module",
"scripts": {
"tsc": "tsc",
"start": "npm run tsc && npm run register-global-commands && node dist/bot.js",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint --fix ./src",
"register-guild-commands": "cross-env REGISTER_MODE=GUILD node dist/handlers/RegisterCommands.js",
"register-global-commands": "cross-env REGISTER_MODE=GLOBAL node dist/handlers/RegisterCommands.js",
"reset-guild-commands": "cross-env REGISTER_MODE=RESET_GUILD node dist/handlers/RegisterCommands.js",
Expand All @@ -15,29 +17,22 @@
"author": "",
"license": "ISC",
"dependencies": {
"@discordjs/builders": "^0.11.0",
"@discordjs/rest": "^0.2.0-canary.0",
"discord-api-types": "^0.26.1",
"discord.js": "^13.6.0",
"discord.js-docs": "github:BenjammingKirby/discord.js-docs#typescriptRewrite",
"dotenv": "^12.0.3",
"fast-xml-parser": "^4.0.1",
"flexsearch": "^0.7.21",
"glob": "^7.2.0",
"node-fetch": "^2.6.6",
"pm2": "^5.1.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was pm2 removed?

Copy link
Author

@eirikhanasand eirikhanasand Dec 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it was installed but there is no reference to it in the code, nor is it referenced by any other dependency neither top level nor sublevel nor any script nor the dockerfile. In other words, I found no indication that it was being used. Saw no reason to include it when it isnt used.

"discord.js": "^14.16.3",
"discord.js-docs": "0.4.3",
"dotenv": "^16.4.5",
"fast-xml-parser": "^4.5.0",
"flexsearch": "^0.7.43",
"glob": "^11.0.0"
},
"devDependencies": {
"@types/flexsearch": "^0.7.2",
"@types/glob": "^7.2.0",
"@types/node": "^17.0.8",
"@types/node-fetch": "^2.5.12",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"@stylistic/eslint-plugin-js": "^2.12.1",
"@types/flexsearch": "^0.7.6",
"@types/glob": "^8.1.0",
"@types/node": "^22.10.0",
"@typescript-eslint/parser": "^8.16.0",
"cross-env": "^7.0.3",
"eslint": "^8.6.0",
"prettier": "^2.5.1",
"ts-node-dev": "^1.1.8",
"typescript": "^4.5.4"
"eslint": "^9.15.0",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.0"
}
}
}
47 changes: 37 additions & 10 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import "dotenv/config";
import { Client, Collection, LimitedCollection } from "discord.js";
import { MyContext } from "./interfaces";
import { loadCommands, interactionCreateHandler } from "./handlers/InteractionCreateHandler";
import { messageHandler } from "./handlers/MessageHandler";
import { deleteButtonHandler } from "./utils/CommandUtils";
import { loadCommands, interactionCreateHandler } from "./handlers/InteractionCreateHandler.js";
import { messageHandler } from "./handlers/MessageHandler.js";
import { deleteButtonHandler } from "./utils/CommandUtils.js";
import {
ActivityType,
Client,
Collection,
GatewayIntentBits,
Interaction,
LimitedCollection,
Partials
} from "discord.js";

(async function () {
const context: MyContext = {
client: new Client({
intents: ["GUILDS", "GUILD_MESSAGES"],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages
],
presence: {
activities: [{ type: "PLAYING", name: "Read the docs" }],
activities: [{ type: ActivityType.Playing, name: "Read the docs" }],
status: "online",
},
// For DMs, a partial channel object is received, in order to receive dms, CHANNEL partials must be activated
partials: ["CHANNEL"],
// For DMs, a partial channel object is received, in order to
// receive dms, Partials.Channel must be activated
partials: [
Partials.Channel
],
makeCache: (manager) => {
//! Disabling these caches will break djs functionality
const unsupportedCaches = [
Expand All @@ -30,7 +44,6 @@ import { deleteButtonHandler } from "./utils/CommandUtils";
},
}),
commands: {
autocompletes: new Collection(),
buttons: new Collection(),
selectMenus: new Collection(),
slashCommands: new Collection(),
Expand All @@ -50,7 +63,21 @@ import { deleteButtonHandler } from "./utils/CommandUtils";
});

docsBot.on("messageCreate", messageHandler);
docsBot.on("interactionCreate", interactionCreateHandler.bind(null, context));
docsBot.on("interactionCreate", (interaction: Interaction<"cached">) => {
interactionCreateHandler(context, interaction);
});

docsBot.login(process.env.TOKEN);
})();

process.on("unhandledRejection", async (err) => {
console.error("Top Level Unhandled Promise Rejection:\n", err);
});

process.on("uncaughtException", async (err) => {
console.error("Top Level Uncaught Promise Exception:\n", err);
});

process.on("uncaughtExceptionMonitor", async (err) => {
console.error("Top Level Uncaught Promise Exception (Monitor):\n", err);
});
Loading