Skip to content

Commit

Permalink
Small changes before v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TFAGaming committed Jan 20, 2024
1 parent 59fa5a2 commit 4ba999b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# <samp>DiscordJS-V14-Bot-Template</samp> v2

The simplified and popular Discord bot commands & events handler built with discord.js version 14 and written in JavaScript. This handler can load up to 4 different type of commands; Prefix, Slash, User context and Message context. It can also handles components; Buttons, Modal submits, Select menus (any type) and autocomplete.
A simplified and popular Discord bot commands & events handler built with discord.js version 14 and written in JavaScript. This handler can load up to 4 different types of commands: Prefix, Slash, User context, and Message context. It can also handle components, including Buttons, Modals, Select menus (any type), and autocomplete.

Did you like my project? Click on the star button (⭐️) right above your screen, thank you!

Expand All @@ -24,7 +24,8 @@ Did you like my project? Click on the star button (⭐️) right above your scre

## Commands, events, and components structure

This Discord bot template uses CommonJS modules. You cannot use `import`, `export` or any related keywords from the ES6 modules.
This Discord bot template uses CommonJS modules. You cannot use `import`, `export`, or any related keywords from the ES6 modules.


### Prefix commands:
```ts
Expand Down Expand Up @@ -90,8 +91,8 @@ module.exports = {
- **dotenv** v^latest
- **mongoose** v^latest

> **Warning**
> Installing any version from the package `chalk` that is over **v2.4.2**, it will throw an error that you must enable ES6 modules, while this handler uses CommonJS modules.
> [!WARNING]
> Installing any version from the package `chalk` that is over **v2.4.2** will throw an error that you must enable ES6 modules, while this handler uses CommonJS modules.
### Platforms:
- **Node.js** v16.9.0 or newer
Expand All @@ -103,8 +104,8 @@ module.exports = {
4. Open VSCode, click on **Open Folder**, and select the new created folder.
5. Go to `src/` and rename `example.config.js` to `config.js` and fill all the required values. You can use ENV instead of `config.js` to keep your bot token and ID, and your MongoDB URI in a secured place by renaming the file `.env.example` to `.env` and filling all required values.

> **Important**
> Sharing your Discord bot's token to anyone is a **very risky** move since you'll **allow them** to **use your bot**. This is also a dangerous move for the MongoDB database, we don't recommend you to use any public URIs or sharing your own database connection URL.
> [!CAUTION]
> Sharing your Discord bot's token with anyone is a very risky move since you'll allow them to use your bot. This is also a dangerous move for the MongoDB database; we don't recommend using any public URIs or sharing your database connection URL.
6. Initialize a new npm package:

Expand Down Expand Up @@ -162,7 +163,7 @@ The component options, each property is optional which means it's allowed to pro
- `public` (**boolean**): If set to true, the component will be available to everyone (default), if set to false, the component will be available to the component owner (original interaction user) only.

## FAQs
### I'm getting this error: "Unable to load application commands to Discord API"
### 1. I'm getting this error: "Unable to load application commands to Discord API"
- The bot token and/or bot ID are invalid.
- The bot token and bot ID are not from the same Discord bot.
- Too many application commands.
Expand All @@ -176,8 +177,11 @@ The component options, each property is optional which means it's allowed to pro

[Learn more...](https://discord.com/developers/docs/interactions/application-commands#registering-a-command)

### Is MongoDB required?
No, MongoDB is not required. There is an option to disable it in `config.js` so you will avoid errors from the commands that requires the database, such as `?prefix`. If you want to use the database, [visit MongoDB website](https://www.mongodb.com/).
### 2. I'm unable to view any application commands, no errors in console?
This is a common problem for developers, to fix this issue, restart the Discord app or go in a different text channel.

### 3. Is MongoDB required?
No, MongoDB is not required. There is an option to disable it in `config.js` so you will avoid errors from the commands that requires the database, such as `?prefix`. If you want to use the database, visit [MongoDB website](https://www.mongodb.com/).

## Contributors
Thank you to all the people who contributed to **DiscordJS-V14-Bot-Template**!
Expand Down
10 changes: 8 additions & 2 deletions src/commands/slash/Utility/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = {
option.setName('fruit')
.setDescription('Choose a fruit')
.setAutocomplete(true)
.setRequired(true)),
.setRequired(true)
),
options: {
public: true
},
Expand All @@ -19,7 +20,12 @@ module.exports = {
* @param {import('discord.js').CommandInteraction} interaction
*/
run: async (client, interaction) => {

const chosenFruit = interaction.options.getString('fruit');
await interaction.reply(`You chose the fruit: ${chosenFruit}`);

await interaction.reply({
content: `You chose the fruit: **${chosenFruit}**`
});

}
};
2 changes: 2 additions & 0 deletions src/components/autocomplete/example-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ module.exports = {
*/
run: async (client, interaction) => {
const fruits = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry', 'Fig', 'Grape', 'Honeydew'];

const currentInput = interaction.options.getFocused();
const filteredFruits = fruits.filter(fruit => fruit.toLowerCase().startsWith(currentInput.toLowerCase()));

await interaction.respond(filteredFruits.map(fruit => ({ name: fruit, value: fruit })));
}
};
9 changes: 5 additions & 4 deletions src/events/Guild/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module.exports = {
ephemeral: true
});
return false;
}
};

return true;
};

Expand All @@ -41,7 +42,7 @@ module.exports = {
}

return;
}
};

if (interaction.isAnySelectMenu()) {
const component = client.collection.components.selects.get(interaction.customId);
Expand All @@ -57,7 +58,7 @@ module.exports = {
}

return;
}
};

if (interaction.isModalSubmit()) {
const component = client.collection.components.modals.get(interaction.customId);
Expand Down Expand Up @@ -85,6 +86,6 @@ module.exports = {
}

return;
}
};
}
};
6 changes: 3 additions & 3 deletions src/events/Guild/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ module.exports = {
let data = cooldown.get(cooldownKey);

if (data.some((v) => v === interaction.commandName)) {
const cooldownMessage = isGlobalCooldown
? config.messageSettings.globalCooldownMessage ?? "Slow down buddy! This command is on a global cooldown"
: config.messageSettings.cooldownMessage ?? "Slow down buddy! You're too fast to use this command";
const cooldownMessage = (isGlobalCooldown
? config.messageSettings.globalCooldownMessage ?? "Slow down buddy! This command is on a global cooldown ({cooldown}s)."
: config.messageSettings.cooldownMessage ?? "Slow down buddy! You're too fast to use this command ({cooldown}s).").replace(/{cooldown}/g, command.options.cooldown / 1000);

await interaction.reply({
content: cooldownMessage,
Expand Down
4 changes: 2 additions & 2 deletions src/events/Guild/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ module.exports = {
if (data.some((v) => v === commandInput)) {
await message.reply({
content:
config.messageSettings.cooldownMessage !== undefined &&
(config.messageSettings.cooldownMessage !== undefined &&
config.messageSettings.cooldownMessage !== null &&
config.messageSettings.cooldownMessage !== ""
? config.messageSettings.cooldownMessage
: "Slow down buddy! You're too fast to use this command.",
: "Slow down buddy! You're too fast to use this command ({cooldown}s).").replace(/{cooldown}/g, command.structure.cooldown / 1000),
});

return;
Expand Down
4 changes: 2 additions & 2 deletions src/example.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ module.exports = {
messageSettings: {
nsfwMessage: "The current channel is not a NSFW channel.",
developerMessage: "You are not authorized to use this command.",
cooldownMessage: "Slow down buddy! You're too fast to use this command.",
globalCooldownMessage: "Slow down buddy! This command is on a global cooldown.",
cooldownMessage: "Slow down buddy! You're too fast to use this command ({cooldown}s).",
globalCooldownMessage: "Slow down buddy! This command is on a global cooldown ({cooldown}s).",
notHasPermissionMessage: "You do not have the permission to use this command.",
notHasPermissionComponent: "You do not have the permission to use this component.",
missingDevIDsMessage: "This is a developer only command, but unable to execute due to missing user IDs in configuration file."
Expand Down

0 comments on commit 4ba999b

Please sign in to comment.