Skip to content

Commit

Permalink
chore: use eslint and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza authored and joeyk710 committed Sep 17, 2024
1 parent f50588a commit 0a35b0f
Show file tree
Hide file tree
Showing 22 changed files with 6,140 additions and 829 deletions.
10 changes: 5 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
DISCORD_TOKEN=
# Your bot's application ID (can be found on Discord or on the Discord Developer Portal)
CLIENT_ID=

# Your bot token
DISCORD_TOKEN=

GUILD_ID=
# Only put an ID here if you want commands to be registered in one server.

CLIENT_ID=
# Your bot's application ID (can be found on Discord or on the Discord Developer Portal)
GUILD_ID=
9 changes: 9 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/eslintrc.json",
"extends": ["neon/common", "neon/node", "neon/typescript", "neon/prettier"],
"ignorePatterns": ["**/dist/*"],
"parserOptions": {
"project": ["./tsconfig.json"]
},
"root": true
}
22 changes: 11 additions & 11 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
- Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down Expand Up @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand Down
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
dist/
node_modules/
.env
# dependencies
node_modules

# env files
.env

# production
dist
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# auto generated
LICENSE

# dependencies
node_modules
package-lock.json
pnpm-lock.yaml
yarn.lock

# production
dist
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://json.schemastore.org/prettierrc.json",
"arrowParens": "avoid",
"endOfLine": "lf",
"printWidth": 120,
"quoteProps": "as-needed"
}
172 changes: 86 additions & 86 deletions .vscode/snippets.code-snippets
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
{
// Place your sample-bot workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Slash command template": {
"prefix": "!slash",
"body": [
"import { ChatInputCommandInteraction, inlineCode } from 'discord.js';",
"import { CommandClass } from '../../structures/command.js';",
"",
"export default new CommandClass({",
" data: {",
" name: 'ping',",
" description: 'Pong!',",
" },",
" opt: {",
" userPermissions: ['SendMessages'],",
" botPermissions: ['SendMessages'],",
" category: 'General',",
" cooldown: 5,",
" visible: true,",
" guildOnly: false,",
" },",
" async execute(interaction: ChatInputCommandInteraction<'cached'>) {",
" const msg = await interaction.reply({",
" content: 'Pinging...',",
" fetchReply: true",
" });",
" setTimeout(() => {",
" const ping = msg.createdTimestamp - interaction.createdTimestamp;",
" interaction.editReply({",
" content: `Pong! Latency is ${inlineCode(`${ping}ms`)}. \\nAPI Latency is ${inlineCode(`${interaction.client.ws.ping}ms`)}`",
" });",
" }, 3000);",
" },",
"})"
],
"description": "Slash command template"
},
"Context menu template": {
"prefix": "!context",
"body": [
"import { ApplicationCommandType, MessageContextMenuCommandInteraction, hyperlink } from 'discord.js';",
"import { CommandClass } from '../../structures/command.js';",
"",
"export default new CommandClass({",
" data: {",
" name: 'echo',",
" type: ApplicationCommandType.Message,",
" },",
" opt: {",
" userPermissions: ['SendMessages'],",
" botPermissions: ['SendMessages'],",
" category: 'Context',",
" cooldown: 5,",
" visible: true,",
" guildOnly: false,",
" },",
" async execute(interaction: MessageContextMenuCommandInteraction<'cached'>) {",
" const message = await interaction.targetMessage.fetch();",
" if (!message?.content) return interaction.reply({",
" content: hyperlink('No content was found in this message!', message.url),",
" ephemeral: true",
" })",
" else return interaction.reply({",
" content: hyperlink(message.content, message.url)",
" });",
" }",
"});",
""
],
"description": "Context menu template"
}
}
// Place your sample-bot workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Slash command template": {
"prefix": "!slash",
"body": [
"import { ChatInputCommandInteraction, inlineCode } from 'discord.js';",
"import { CommandClass } from '../../structures/command.js';",
"",
"export default new CommandClass({",
" data: {",
" name: 'ping',",
" description: 'Pong!',",
" },",
" opt: {",
" userPermissions: ['SendMessages'],",
" botPermissions: ['SendMessages'],",
" category: 'General',",
" cooldown: 5,",
" visible: true,",
" guildOnly: false,",
" },",
" async execute(interaction: ChatInputCommandInteraction<'cached'>) {",
" const msg = await interaction.reply({",
" content: 'Pinging...',",
" fetchReply: true",
" });",
" setTimeout(() => {",
" const ping = msg.createdTimestamp - interaction.createdTimestamp;",
" interaction.editReply({",
" content: `Pong! Latency is ${inlineCode(`${ping}ms`)}. \\nAPI Latency is ${inlineCode(`${interaction.client.ws.ping}ms`)}`",
" });",
" }, 3000);",
" },",
"})",
],
"description": "Slash command template",
},
"Context menu template": {
"prefix": "!context",
"body": [
"import { ApplicationCommandType, MessageContextMenuCommandInteraction, hyperlink } from 'discord.js';",
"import { CommandClass } from '../../structures/command.js';",
"",
"export default new CommandClass({",
" data: {",
" name: 'echo',",
" type: ApplicationCommandType.Message,",
" },",
" opt: {",
" userPermissions: ['SendMessages'],",
" botPermissions: ['SendMessages'],",
" category: 'Context',",
" cooldown: 5,",
" visible: true,",
" guildOnly: false,",
" },",
" async execute(interaction: MessageContextMenuCommandInteraction<'cached'>) {",
" const message = await interaction.targetMessage.fetch();",
" if (!message?.content) return interaction.reply({",
" content: hyperlink('No content was found in this message!', message.url),",
" ephemeral: true",
" })",
" else return interaction.reply({",
" content: hyperlink(message.content, message.url)",
" });",
" }",
"});",
"",
],
"description": "Context menu template",
},
}
74 changes: 36 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About

This sample Discord bot written in TypeScript is a great starting place for creating the bot of your ✨ _dreams_ ✨.
This sample Discord bot written in TypeScript is a great starting place for creating the bot of your ✨ _dreams_ ✨.

Primarily using [discord.js](https://discord.js.org/#/) with examples used from the [discord.js guide](https://discordjs.guide).

Expand All @@ -10,48 +10,47 @@ Features include (but not limited to):
- Starter Slash & Context-Menu Commands
- Optional per-command cooldowns & User / Client permission checking

> [!IMPORTANT]
> **The latest [Node LTS (Long-Term Support) Version](https://nodejs.org) is required**
> [!IMPORTANT] > **The latest [Node LTS (Long-Term Support) Version](https://nodejs.org) is required**
## Getting Started 🎉

1. Clone the repository here on Github or from terminal (shown below)

```bash
git clone https://github.com/joeyk710/sample-discordjs-bot.git
cd sample-discordjs-bot
```
```bash
git clone https://github.com/joeyk710/sample-discordjs-bot.git
cd sample-discordjs-bot
```

2. Rename [.env.example](.env.example) to `.env`

3. Open the [.env](.env.example) file and fill in the required values as shown below

```env
DISCORD_TOKEN=
# Your bot token
```env
DISCORD_TOKEN=
# Your bot token
GUILD_ID=
# Only put an ID here if you want commands to be registered in one server.
GUILD_ID=
# Only put an ID here if you want commands to be registered in one server.
CLIENT_ID=
# Your bot's application ID (can be found on Discord or on the Discord Developer Portal)
```
CLIENT_ID=
# Your bot's application ID (can be found on Discord or on the Discord Developer Portal)
```

4. Installing dependencies

```bash
npm install
yarn install
pnpm install
```
```bash
npm install
yarn install
pnpm install
```

5. Deploying Commands

```bash
npm run deploy
yarn run deploy
pnpm run deploy
```
```bash
npm run deploy
yarn run deploy
pnpm run deploy
```

> [!NOTE]
> If there is no `GUILD_ID` in the **[.env](.env.example)** file, commands will be registered **_globally_**.
Expand All @@ -60,28 +59,27 @@ Features include (but not limited to):
6. Starting the bot

```bash
npm run start
yarn run start
pnpm run start
```
```bash
npm run start
yarn run start
pnpm run start
```

## Sample Commands 🤖

Name | Description
| - | - |
[/ping](src/commands/general/ping.ts) | Responds with "Pong!"
| [Echo](src/commands/context/echo.ts) | Echoes the message selected in the channel the command was sent in
| Name | Description |
| ------------------------------------- | ------------------------------------------------------------------ |
| [/ping](src/commands/general/ping.ts) | Responds with "Pong!" |
| [Echo](src/commands/context/echo.ts) | Echoes the message selected in the channel the command was sent in |

____
---

> [!NOTE]
> Please check the [discord.js docs](https://discord.js.org), [discord.js guide](https://discordjs.guide), and [discord-api-types](https://discord-api-types.dev) for proper types, properties and method usage.
>
>
> You will notice the current discord.js guide uses `@discordjs/builders` for command creation. This template uses raw objects for creating commands which makes use of enum types [ApplicationCommandType](https://discord-api-types.dev/api/discord-api-types-v10/enum/ApplicationCommandType) and [ApplicationCommandOptionType](https://discord-api-types.dev/api/discord-api-types-v10/enum/ApplicationCommandOptionType).
>
>
> ⚠️ ***This template assumes you have a general understanding of TypeScript*** ⚠️
> ⚠️ **_This template assumes you have a general understanding of TypeScript_** ⚠️
## Issues 💭

Expand Down
Loading

0 comments on commit 0a35b0f

Please sign in to comment.