Discord js typescript template

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A public TypeScript Discord.js v14 bot template.

License

Hauntmore/TypeScript-Discord.js-Bot-Template

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

TypeScript Discord.js Bot Template

You are expected to know the basic fundamentals of JavaScript, TypeScript, Node.js. It would also be useful if you know basic usage of your device’s operating system.

  1. You are required to have ‘Node.js’ v16.9 (~v7.21.1 npm) or above!
  2. Discord.js v14.2.0.
  1. Setting up dotenv files.
    • Remove .example from the production.env.example , development.env.example , and .env.example files.
  2. Obtain a bot token and bot Id.
    • You’ll need to create a new bot in your Discord Developer Portal application dashboard.
      • At the end you should have a Bot Token.
  3. Modify the dotenv files.
    • Open the production.env file.
    • Insert your bot token as the value of DISCORD_TOKEN .
    • Insert your bot Id as the value of CLIENT_ID .
    • Do the same steps for development.env .
    • Inside the .env file, either use «development» or «production» for the NODE_ENV key. The key production will use the production.env file, and development will use the development.env file.
  4. Install the needed dependencies.
    • Navigate into the installed source files and type npm install .
  5. Register commands.
    • In order to use application commands, they first have to be registered.
    • Type npm run deploy-commands to register the bot’s application commands globally.
      • Run this script any time you change a command name, structure, or add/remove commands, etc.
      • This is so Discord knows what your commands look like.
      • Command deployments should be almost instant whether it is being deployed in a guild or globally.
Читайте также:  Php csv count lines

Disclaimer We also have .replit and start.bat files you can use, along with a Procfile for Heroku but you must change the scripts yourselves if you do not want the one that is currently set.

Docker will be in the works, no ETA is set for this.

You can run the bot in multiple modes:

  1. Normal Mode
    • Type npm run start:bot .
    • This starts a single instance of the bot.
  2. Sharding Mode
    • Type npm start .
    • Starts the bot with sharding.
  3. PM2 Mode
    • Note: You may have to run this as an Administrator in order to use this or you may get a Permission Denied error. This may apply to other scripts inside package.json and should be handled accordingly.
    • Inside process.json you will see this object: env: < "NODE_ENV": "development" >, you are free to change it as it acts as the .env ‘s NODE_ENV key. Change it either to production or keep it as development.
    • Type npm run start:pm2 .
    • This is similar to Sharding Mode but it also uses PM2 to manage processes.

About

A public TypeScript Discord.js v14 bot template.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A TypeScript Discord bot template (discord.js v14)

License

ppauel/typescript-discord-bot

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Discord.js Bot Template

TypeScript Discord Bot Template

A multi-purpose discord.js v14 bot template. This is the successor of the djs-template repository.

  • Slash Command Handler (global / guild)
  • Context Menu Handler (global / guild)
  • Interaction Handler (Message Components, Modals)
  • Event Handler
  • Sharding
  • Localizations
  • Customizable configuration
  • Examples

Install the required npm modules.

Create a new file called .env in the root directory and insert your bot token as shown in the example.env file.

Читайте также:  Принадлежность точки прямоугольнику python

Apart from the token, the configuration takes place in the config.json file located in the src/ folder.

Specify a guild ID to which the guild commands will be deployed. Make sure that the bot is a member of this server and has sufficient permissions to create commands.

Choose if you want to receive message components and modals using the interaction handler.

"receiveMessageComponents": true, "receiveModals": true

Select whether to reply with a warning if an error occurs whilst executing an interaction.

Choose whether you want to split the custom ID of an interaction by underscores (_). In this case, the interaction handler uses only the string before the first underscore (if any). This system makes sense if you want to use the custom ID to convey additional information.

For example report_527814442746904591 is treated as report .

If you want to use global commands only, you can disable guild commands. The global attribute must still be true .

Done! You can now experiment with some examples. For that, you just need to start your bot.

The bot can be started as a single instance or in processes intended for sharding. For smaller bots, the first variant should be sufficient.

To build & start the bot without sharding run

To build & start the sharding manager run

During development, it is a good idea not to deploy all commands every time you restart. You can use the following command to disable automatic deployment and run the uncompiled bot / manager.

To only compile a JavaScript build of your bot, run this command.

The finished build will be located in the dist/ directory.

This template contains some sample commands and interactions so you understand how to use it:

  • src/commands/example/ping.ts Ping Command
  • src/features/ping.ts Ping Button Builder
  • src/interactions/buttons/example/ping.ts Ping Button Interaction
  • src/context_menus/example/countCharacters.ts Message Context Menu
  • src/context_menus/example/displayAvatar.ts User Context Menu

Hint: Commands, Context Menus and Interactions have to be located in a subfolder.

To make it easier to access the client’s config and collections, the template includes the ExtendedClient class. It allows to access these properties directly from the client without importing them.

const client = new ExtendedClient(); const guildId = client.config.guild;

However, the ExtendedClient cannot be accessed through an API object such as message or an interaction. The included handlers pass the _client as its own parameter, so you don’t have to worry about that.

By default, this project supports translations. These are managed in the lang/ folder. The configuration is located in src/features/i18n.ts . Examples of usage can be found in the demo files.

This template is still under development and will be constantly extended, for example when changes are made to the Discord API.

About

A TypeScript Discord bot template (discord.js v14)

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Читайте также:  Скомпилировать exe на питоне

A simple startup codebase for a discord.js bot built with typescript

License

TeloiDev/typescript-discord.js-template

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

TypeScript discord.js template

This repo was made so everyone can easily start their discord.js bots with typescript!

In order to start with this template first you need to install this repo with git clone typescript-discord.js-template or just download it through GitHub.

Once you’re done remove every .example from files’ and directories’ names and run npm install .

The purpose of TypeScript is to strongly type your code so you need to set up everything in types/ directory.

This is the default state of Command interface. You can add any other properity that you need.

import  Message > from "discord.js"; // If you need any other properities for a command add them here declare module "discord.js"  export interface Command  name: string; description: string; isTypescriptFun: boolean; expectedArgsAmount: number; // etc. run: (message: Message, args: string[]) => void; > >

Same aplies to Client interface. This is it’s default state and here’s how you can change it to your needs.

import  Collection > from "discord.js"; // In case you need any other collectors add them here declare module "discord.js"  export interface Client  commands: Collectionunknown, Command>; aliases: Collectionunknown, any>; // Using any should be a final decission and you shouldn't use it unless it's necessary > >

I don’t think I have to explain this. Just modify it so you can actually use the bot

DISCORD_TOKEN=your discord bot token

You can find your bot’s prefix in messageCreate.ts file.

Adding new Commands and Events

Remember to name your event files same as the actual event’s name.

Example: if an event is called «messageDelete» name your file «messageDelete.ts» etc.

Pretty straightforward. Just make sure that every command has a unique name.

As always every contributions is welcome. For major changes open an issue first and describe what you want to change

About

A simple startup codebase for a discord.js bot built with typescript

Источник

Оцените статью