Giter Site home page Giter Site logo

namvr / discordbot-template Goto Github PK

View Code? Open in Web Editor NEW
317.0 317.0 72.0 178 KB

A boilerplate / template for discord.js v14 bots with 100% coverage of Discord API, command handler, error handler based on https://discordjs.guide/

Home Page: https://djs.docs.namanvrati.cf/

License: Apache License 2.0

JavaScript 100.00%
boilerplate-template buttons command-handler context-menus discord discord-api discord-bot discord-bot-template discord-js discord-ts discordjs error-handler nodejs select-menus slash-commands typescript typings v14 vsc

discordbot-template's Introduction

Hi there ๐Ÿ‘‹

Welcome! This is Naman - a passionate developer who loves to code - https://namanvrati.me/ (my blog)!

  • ๐Ÿ’ฌ Ask me about: Anything! Ding me on discord: allroundernaman#3915
  • ๐Ÿ“ซ How to reach me: Discord or Email: [email protected]
  • ๐Ÿ˜„ Pronouns: Male, He/Him

discordbot-template's People

Contributors

goudronviande24 avatar krishgarg avatar mr-leonerrr avatar namvr avatar stormpacer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discordbot-template's Issues

[BUG] START BOT

Describe the bug
PROBLEM IN START BOT

To reproduce
npm i
nodemon bot.js

Expected behaviour
Problem in start bot

Screenshots
image

image

[BUG] Select-Menus don't work

Select Menus don't work, can be fixed by adding the following into bot.js

/**********************************************************************/
// Registration of select-menus Interactions

/**
 * @type {String[]}
 * @description All Context Menu commands.
 */

 const selectMenus = fs.readdirSync("./interactions/select-menus");

 // Loop through all files and store select-menus in slashCommands collection.
 
 for (const folder of selectMenus) {
	 const files = fs
		 .readdirSync(`./interactions/select-menus/${folder}`)
		 .filter((file) => file.endsWith(".js"));
	 for (const file of files) {
		 const menus = require(`./interactions/select-menus/${folder}/${file}`);
		 const keyName = `${menus.id}`;
		 client.selectCommands.set(keyName, menus);
	 }
 }

Yes im too lazy to fork it and PR it

[HELP] command permissions

How can you set role permissions for command usage? I'm not able to find it in the example ones except for ownerOnly

thanks

Slash Commands Permissions

Hi,
Now that we have .setDefaultMemberPermissions to set permissions for commands in SlashCommandBuilder for slash commands. How can I check if check if the user typing the command has the command? I was thinking about the help command to list all commands so I can only display available commands for the user typing the command.

Example if one command has .setDefaultMemberPermissions(PermissionFlagsBits.BanMembers), and a user without that permission types the help command in slash to list all available commands. How can we hide that command from being displayed as the user doesnt have access?

[BUG] Button issue

Describe the bug
I made a command with a button (a prefix command), when i try linking the button or pressing it without even linking it, it crashes and says that command is undefined in slashCreate, thing is, i didn't touch slashCreate while making this, and command is defined in that file, else no slash command would even work.
Error

TypeError: Cannot read properties of undefined (reading 'data')
    at Object.execute (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\events\slashCreate.js:27:30)
    at Client.<anonymous> (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\bot.js:60:35)
    at Client.emit (node:events:526:35)
    at InteractionCreateAction.handle (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
    at module.exports [as INTERACTION_CREATE] (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
    at WebSocketManager.handlePacket (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
    at WebSocketManager.<anonymous> (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
    at WebSocketManager.emit (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
    at WebSocketShard.<anonymous> (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\@discordjs\ws\dist\index.js:1173:51)
    at WebSocketShard.emit (C:\Users\ODHG1\Desktop\new dashybot\frankybot-remake\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:397:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Additional context
Here is my slashCreate (i only added cooldowns following the djs guide):

/**
 * @file Slash Command Interaction Handler
 * @author Naman Vrati
 * @since 3.0.0
 * @version 3.3.0
 */
const {Collection} = require("discord.js");

module.exports = {
	name: "interactionCreate",

	/**
	 * @description Executes when an interaction is created and handle it.
	 * @author Naman Vrati
	 * @param {import('discord.js').CommandInteraction & { client: import('../typings').Client }} interaction The interaction which was created
	 */

	async execute(interaction) {
		
		// Deconstructed client from interaction object.
		const { client } = interaction;

		// Checks if the interaction is a command (to prevent weird bugs)
		const { cooldowns } = interaction.client;
		const command = client.slashCommands.get(interaction.commandName);

		if (!cooldowns.has(command.data.name)) {
			cooldowns.set(command.data.name, new Collection());
		}

		const now = Date.now();
		const timestamps = cooldowns.get(command.data.name);
		const defaultCooldownDuration = 3;
		const cooldownAmount = (command.cooldown ?? defaultCooldownDuration) * 1_000;

		if (timestamps.has(interaction.user.id)) {
			const expirationTime = timestamps.get(interaction.user.id) + cooldownAmount;
		
			if (now < expirationTime) {
				const expiredTimestamp = Math.round(expirationTime / 1_000);
				return interaction.reply({ content: `Please wait, you are on a cooldown for \`${command.data.name}\`. You can use it again <t:${expiredTimestamp}:R>.`, ephemeral: true });
			}
		}
				
		timestamps.set(interaction.user.id, now);
		setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount);

		if (!interaction.isChatInputCommand()) return;


		// If the interaction is not a command in cache.

		if (!command) return;

		// A try to executes the interaction.

		try {
			await command.execute(interaction);
		} catch (err) {
			console.error(err);
			await interaction.reply({
				content: "There was an issue while executing that command!",
				ephemeral: true,
			});
		}


	},
};

Line 60 in bot.js is async (...args) => await event.execute(...args, client)
Whole loop would be

for (const file of eventFiles) {
	const event = require(`./events/${file}`);
	if (event.once) {
		client.once(event.name, (...args) => event.execute(...args, client));
	} else {
		client.on(
			event.name,
			async (...args) => await event.execute(...args, client)
		);
	}
}

[BUG] Issue utilising trigger based commands when multiple exist

Issue
When attempting to register multiple files within either commands or triggers/reactions (only tested these two), the bot is only regestering the first command it locates within the file strucure (typically alphabetically). The only slash command the bot is capable of executing is the help command for instance.

To reproduce
I am using the repo exactly as is when cloned, except -of course- for adding the config.json file with my details. For testing purposes I provided my bot all bot permissions via the discord develeoper portal, as well as all privileged gateway intents. I figure the only difference between my codebase and yours is my node and npm versions (npm: 9.5.1, node: 18.16.0).

Expected behaviour
I expect copying the hello.js file in triggers/reactions to the same directory and renaming to hello2.js with different names exported from the module.exports would allow each to function when called upon with it's name (I am using unique names). Or even that the provided commands in the /command folder would work. Rather than simply the help command.

Screenshots
Please let me know if you need any!

Additional context
There's a posibility I am doing something wrong here, but I've been bashing my head against a wall trying to sort it out for a few hours and have tried multiple configurations before eventually establishing that it wouldnt even work directly after a git clone.

Add Mongo Support

Suggestion
Not a bug, Maybe add mongo support to the template or please describe how i can do it.

Suggestion: Add sharding

It'd be great if you could add sharding to this! Either auto or manual(like an option for us in config.json to enable/disable sharding).

There is a package I know of, Discord-Hybrid-Sharding, that allows you to save a lot of resources while sharding(up to 60% resources
can be saved!). Maybe it could be used?

[HELP] Unwanted Slash Interactions Visible

When I run the bot and look at the slash commands through Discord, I see is has commands like /admin embed, /admin say, /info ping, and /info userinfo. I want to get rid of these but I can't find them anywhere in the bots files.
2021-10-17 (2)

[BUG] guildMemberAdd not emitting

I tried to use the event but the print 'test' did not appear

/**
 * @file Context Interaction Handler
 * @author Krish Garg & Naman Vrati
 * @since 3.0.0
 * @version 3.3.0
 */

module.exports = {
	name: "guildMemberAdd",

	/**
	 * @description Executes when client is ready (bot initialization).
	 * @param {import('../typings').Client} client Main Application Client.
	 */
	execute(client, guild, member) {
        console.log('test')
	},
};

[BUG] guildMemberUpdate not emitting

Hi,

I've placed a guildMemberUpdate.js file under events, with this being the basic code in it:

const { MessageEmbed } = require("discord.js");

module.exports = {
    name: "guildMemberUpdate",

    execute: async (oldMember, newMember) => {
        console.log("test");
    },
};

for some reason, "test" is not being printed in the console whenever i remove or add a role to a member

[BUG] The optional field in the help slash command is useless

Describe the bug
When you use the help slash command with the "command" option, it changes nothing and still responds only the "general help".

To reproduce

  • Start the bot
  • Execute /help [anything]
  • Whatever you write, it's still going to answer the same as if you put nothing

Expected behaviour
It should do like the traditional !help command, general help when no options, and help about a specific command when given.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.