Skip to content

Commit

Permalink
V1.0.6 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
RileCraft committed Feb 9, 2024
1 parent ebbfc98 commit d2b17e2
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 20 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<img src="https://media.discordapp.net/attachments/774290264764055582/1093484780525469757/A_banner_for_a_discord_bots_template_made_using_discord.js.png" height="200" width="400"><br>
<img src="https://img.shields.io/badge/version-1.0.5-05122A?style=for-the-badge">
<img src="https://img.shields.io/badge/version-1.0.6-05122A?style=for-the-badge">
<a href="https://discord.gg/VStdRr8nP2"><img src="https://img.shields.io/badge/discord-invite-5865f2?style=for-the-badge&logo=discord&logoColor=white"></a>
<img src="https://img.shields.io/github/issues/RileCraft/DiscordBot-Template-ts.svg?style=for-the-badge">
<img src="https://img.shields.io/github/forks/RileCraft/DiscordBot-Template-ts.svg?style=for-the-badge">
Expand All @@ -12,9 +12,10 @@
The Discord Bot Template provides a solid foundation for creating feature-rich Discord bots using Discord.js. It includes various managers for handling message commands, buttons, select menus, slash commands, context menus, and modal forms. The template offers customization options, colorful logging, and a simple code structure.

## Changelog
### IMPORTANT UPDATE 1.0.5
### IMPORTANT UPDATE 1.0.6

- **Fixed Windows Support and SlashCommands & ContextMenus not Registering.**
- Fixed subDirectories not working for commands.
- Latest Discord.js adaptation.
- Following JavaScript Naming Convention.
- Removed `node-recursive-directory` dependency.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discordbot-template-ts",
"version": "1.0.5",
"version": "1.0.6",
"description": "TypeScript version of DiscordBot-Template",
"main": "./src/bot.ts",
"type": "module",
Expand Down
5 changes: 2 additions & 3 deletions src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ActivityType, DiscordClient } from "discord.js";
import { rootPath } from "../bot.js";
import { pathToFileURL } from "node:url";
import { ClientEvent, ContextMenu, SlashCommand } from "../types.js";
import { fileReader } from "../utils/fileReader.js";
import { t } from "tasai";
Expand All @@ -15,15 +14,15 @@ export const Event: ClientEvent = {

let allSlashCommands: Array<string> = fileReader(`${rootPath}/interactions/slashCommands`);
allSlashCommands = await allSlashCommands.reduce(async(array: any, slash: string): Promise<Array<string>> => {
const command: SlashCommand | undefined = (await import(pathToFileURL(slash).href))?.Slash;
const command: SlashCommand | undefined = (await import(`file:///${slash}`))?.Slash;

if (command?.ignore || !command?.name) return array;
else return (await array).concat(slash)
}, []);

let allContextMenus: Array<string> = fileReader(`${rootPath}/interactions/contextMenus`);
allContextMenus = await allContextMenus.reduce(async(array: any, context: string): Promise<Array<string>> => {
const command: ContextMenu | undefined = (await import(pathToFileURL(context).href))?.Context;
const command: ContextMenu | undefined = (await import(`file:///${context}`))?.Context;

if (command?.ignore || !command?.name || !command?.type) return array;
else return (await array).concat(context)
Expand Down
3 changes: 1 addition & 2 deletions src/structures/managers/buttonCommands.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { DiscordClient } from "discord.js";
import { ButtonCommand } from "../../types.js";
import { pathToFileURL } from "node:url";
import { fileReader } from "../../utils/fileReader.js";

export const ButtonManager = async(client: DiscordClient, rootPath: string): Promise<void> => {
const buttonCommandFiles: Array<string> = fileReader(`${rootPath}/interactions/buttons`);
if (!buttonCommandFiles.length) return;

for (const buttonCommandFile of buttonCommandFiles) {
const buttonCommand: ButtonCommand = (await import(pathToFileURL(buttonCommandFile).href))?.Button;
const buttonCommand: ButtonCommand = (await import(`file:///${buttonCommandFile}`))?.Button;
if (!buttonCommand) continue;

if (!buttonCommand?.ignore && buttonCommand?.name) client.buttonCommands?.set(buttonCommand?.name, buttonCommand);
Expand Down
3 changes: 1 addition & 2 deletions src/structures/managers/events.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { DiscordClient } from "discord.js";
import { ClientEvent } from "../../types.js";
import { pathToFileURL } from "node:url";
import { fileReader } from "../../utils/fileReader.js";

export const EventManager = async(client: DiscordClient, rootPath: string): Promise<void> => {
const eventFiles: Array<string> = fileReader(`${rootPath}/events`);
if (!eventFiles.length) return;

for (const event of eventFiles) {
const clientEvent: ClientEvent = (await import(pathToFileURL(event).href))?.Event;
const clientEvent: ClientEvent = (await import(`file:///${event}`))?.Event;
if (clientEvent.ignore) continue;

client.events?.set(clientEvent.name, clientEvent);
Expand Down
3 changes: 1 addition & 2 deletions src/structures/managers/messageCommands.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { MessageCommand } from "../../types.js";
import { DiscordClient } from "discord.js";
import { pathToFileURL } from "node:url";
import { fileReader } from "../../utils/fileReader.js";

export const MessageCMDManager = async(client: DiscordClient, rootPath: string): Promise<void> => {
const messageCommandsFiles: Array<string> = fileReader(`${rootPath}/messageCommands`);
if (!messageCommandsFiles.length) return;

for (const messageCommandFile of messageCommandsFiles) {
const messageCommand: MessageCommand = (await import(pathToFileURL(messageCommandFile).href))?.MsgCommand;
const messageCommand: MessageCommand = (await import(`file:///${messageCommandFile}`))?.MsgCommand;
if (!messageCommand) continue;

if (!messageCommand.ignore && messageCommand.name) client.messageCommands?.set(messageCommand.name.toLowerCase(), messageCommand);
Expand Down
3 changes: 1 addition & 2 deletions src/structures/managers/modalForms.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { DiscordClient } from "discord.js";
import { ModalForm } from "../../types.js";
import { pathToFileURL } from "node:url";
import { fileReader } from "../../utils/fileReader.js";

export const ModalManager = async(client: DiscordClient, rootPath: string): Promise<void> => {
const modalFormFiles: Array<string> = fileReader(`${rootPath}/interactions/modalForms`);
if (!modalFormFiles.length) return;

for (const modalFormFile of modalFormFiles) {
const modalForm: ModalForm = (await import(pathToFileURL(modalFormFile).href))?.Modal;
const modalForm: ModalForm = (await import(`file:///${modalFormFile}`))?.Modal;
if (!modalForm) continue;

if (!modalForm.ignore && modalForm.name) client.modalForms?.set(modalForm.name, modalForm);
Expand Down
3 changes: 1 addition & 2 deletions src/structures/managers/selectMenus.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { SelectMenu } from "../../types.js";
import { DiscordClient } from "discord.js";
import { pathToFileURL } from "node:url";
import { fileReader } from "../../utils/fileReader.js";

export const SelectMenuManager = async(client: DiscordClient, rootPath: string): Promise<void> => {
const selectMenuFiles: Array<string> = fileReader(`${rootPath}/interactions/selectMenus`);
if (!selectMenuFiles.length) return;

for (const selectMenuFile of selectMenuFiles) {
const selectMenu: SelectMenu = (await import(pathToFileURL(selectMenuFile).href))?.Menu;
const selectMenu: SelectMenu = (await import(`file:///${selectMenuFile}`))?.Menu;
if (!selectMenu) continue;

if (!selectMenu.ignore && selectMenu.name) client.selectMenus?.set(selectMenu.name, selectMenu);
Expand Down
5 changes: 2 additions & 3 deletions src/structures/managers/slashCommands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ApplicationCommandType, DiscordClient, REST, Routes } from "discord.js";
import { ContextMenu, SlashCommand, SlashCommandOptions } from "../../types.js";
import { fileReader } from "../../utils/fileReader.js";
import { pathToFileURL } from "node:url";

export const SlashManager = async (client: DiscordClient, rootPath: string): Promise<void> => {
const allSlashCommandsFiles = fileReader(`${rootPath}/interactions/slashCommands`);
Expand Down Expand Up @@ -31,7 +30,7 @@ export const SlashManager = async (client: DiscordClient, rootPath: string): Pro

if (allSlashCommandsFiles.length > 0) {
for (const slashCommandFile of allSlashCommandsFiles) {
const slashCommand: SlashCommand | undefined = (await import(pathToFileURL(slashCommandFile).href))?.Slash;
const slashCommand: SlashCommand | undefined = (await import(`file:///${slashCommandFile}`))?.Slash;
if (!slashCommand) continue;

if (slashCommand?.ignore || !slashCommand?.name || !slashCommand.description) continue;
Expand Down Expand Up @@ -61,7 +60,7 @@ export const SlashManager = async (client: DiscordClient, rootPath: string): Pro

if (allContextMenusFiles.length > 0) {
for (const contextMenuFile of allContextMenusFiles) {
const contextMenu: ContextMenu | undefined = (await import(pathToFileURL(contextMenuFile).href))?.Context;
const contextMenu: ContextMenu | undefined = (await import(`file:///${contextMenuFile}`))?.Context;
if (!contextMenu) continue;

if (contextMenu?.ignore || !contextMenu?.name || !contextMenu?.type) continue;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/fileReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const fileReader = (dir: string): Array<string> => {
const stats = statSync(filePath);

if (stats.isFile() && extname(filePath) === ".js") files.push(filePath);
else if (stats.isDirectory()) files.push(...fileReader(filePath));
else if (stats.isDirectory()) files.push(...fileReader(`file:///${filePath}`));
};

return files;
Expand Down

0 comments on commit d2b17e2

Please sign in to comment.