Skip to content

Commit 736b870

Browse files
committed
Initial commit from discordx
0 parents  commit 736b870

15 files changed

Lines changed: 598 additions & 0 deletions

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# files
2+
.vscode
3+
.env
4+
.env.local
5+
package-lock.json
6+
yarn.lock
7+
8+
# folders
9+
build
10+
node_modules

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## build runner
2+
FROM node:lts-alpine as build-runner
3+
4+
# Set temp directory
5+
WORKDIR /tmp/app
6+
7+
# Move package.json
8+
COPY package.json .
9+
10+
# Install dependencies
11+
RUN npm install
12+
13+
# Move source files
14+
COPY src ./src
15+
COPY tsconfig.json .
16+
17+
# Build project
18+
RUN npm run build
19+
20+
## producation runner
21+
FROM node:lts-alpine as prod-runner
22+
23+
# Set work directory
24+
WORKDIR /app
25+
26+
# Copy package.json from build-runner
27+
COPY --from=build-runner /tmp/app/package.json /app/package.json
28+
29+
# Install dependencies
30+
RUN npm install --only=production
31+
32+
# Move build files
33+
COPY --from=build-runner /tmp/app/build /app/build
34+
35+
# Start bot
36+
CMD [ "npm", "run", "start" ]

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<div>
2+
<p align="center">
3+
<a href="https://discordx.js.org" target="_blank" rel="nofollow">
4+
<img src="https://discordx.js.org/discordx.svg" width="546" />
5+
</a>
6+
</p>
7+
<p align="center">
8+
<a href="https://discordx.js.org/discord"
9+
><img
10+
src="https://img.shields.io/discord/874802018361950248?color=5865F2&logo=discord&logoColor=white"
11+
alt="Discord server"
12+
/></a>
13+
<a href="https://www.npmjs.com/package/discordx"
14+
><img
15+
src="https://img.shields.io/npm/v/discordx.svg?maxAge=3600"
16+
alt="NPM version"
17+
/></a>
18+
<a href="https://www.npmjs.com/package/discordx"
19+
><img
20+
src="https://img.shields.io/npm/dt/discordx.svg?maxAge=3600"
21+
alt="NPM downloads"
22+
/></a>
23+
<a href="https://github.com/oceanroleplay/discord.ts/actions"
24+
><img
25+
src="https://github.com/oceanroleplay/discord.ts/workflows/Build/badge.svg"
26+
alt="Build status"
27+
/></a>
28+
<a href="https://www.paypal.me/vijayxmeena"
29+
><img
30+
src="https://img.shields.io/badge/donate-paypal-F96854.svg"
31+
alt="paypal"
32+
/></a>
33+
</p>
34+
<p align="center">
35+
<b> Create a discord bot with TypeScript and Decorators! </b>
36+
</p>
37+
</div>
38+
39+
# 📖 Introduction
40+
41+
A starter template equipped with several interaction commands and one event.
42+
43+
# 🏗 Development
44+
45+
```
46+
npm install
47+
npm run dev
48+
```
49+
50+
If you want to use [Nodemon](https://nodemon.io/) to auto-reload while in development:
51+
52+
```
53+
npm run watch
54+
```
55+
56+
# 💻 Production
57+
58+
```
59+
npm install --production
60+
npm run build
61+
npm run start
62+
```
63+
64+
# 🐋 Docker
65+
66+
To start your application:
67+
68+
```
69+
docker-compose up -d
70+
```
71+
72+
To shut down your application:
73+
74+
```
75+
docker-compose down
76+
```
77+
78+
To view your application's logs:
79+
80+
```
81+
docker-compose logs
82+
```
83+
84+
For the full command list please view the [Docker Documentation](https://docs.docker.com/engine/reference/commandline/cli/).
85+
86+
# 📜 Documentation
87+
88+
- [discordx.js.org](https://discordx.js.org)
89+
- [Tutorials (dev.to)](https://dev.to/oceanroleplay/series/14317)
90+
91+
# ☎️ Need help?
92+
93+
- [Check frequently asked questions](https://discordx.js.org/docs/faq)
94+
- [Check examples](https://github.com/oceanroleplay/discord.ts/tree/main/packages/discordx/examples)
95+
- Ask in the community [Discord server](https://discordx.js.org/discord)
96+
97+
# 💖 Thank you
98+
99+
You can support [discordx](https://www.npmjs.com/package/discordx) by giving it a [GitHub](https://github.com/oceanroleplay/discord.ts) star.

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: "3"
2+
services:
3+
app:
4+
build: .
5+
command: node build/main.js
6+
environment:
7+
- BOT_TOKEN=${BOT_TOKEN}

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "botsofcode",
3+
"version": "1.0.0",
4+
"private": true,
5+
"license": "MIT",
6+
"type": "module",
7+
"main": "build/main.js",
8+
"scripts": {
9+
"build": "tsc",
10+
"build:changelog": "npx @discordx/changelog --root=src",
11+
"dev": "ts-node-esm src/main.ts",
12+
"start": "node build/main.js",
13+
"watch": "nodemon --exec ts-node-esm src/main.ts"
14+
},
15+
"dependencies": {
16+
"@discordx/importer": "^1.1.10",
17+
"@discordx/pagination": "^3.2.0",
18+
"discord.js": "^14.4.0",
19+
"discordx": "^11.3.0"
20+
},
21+
"devDependencies": {
22+
"@types/node": "^18.7.18",
23+
"nodemon": "^2.0.20",
24+
"prettier": "^2.7.1",
25+
"ts-node": "^10.9.1",
26+
"typescript": "4.8.3"
27+
},
28+
"engines": {
29+
"node": ">=16.0.0",
30+
"npm": ">=7.0.0"
31+
}
32+
}

src/commands/choices.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { CommandInteraction } from "discord.js";
2+
import { ApplicationCommandOptionType } from "discord.js";
3+
import { Discord, Slash, SlashChoice, SlashOption } from "discordx";
4+
5+
@Discord()
6+
export class Example {
7+
@Slash({ description: "choose" })
8+
choose(
9+
@SlashChoice("Human", "Astronaut", "Dev")
10+
@SlashOption({
11+
description: "What are you?",
12+
name: "what",
13+
required: true,
14+
type: ApplicationCommandOptionType.String,
15+
})
16+
what: string,
17+
interaction: CommandInteraction
18+
): void {
19+
interaction.reply(what);
20+
}
21+
22+
@Slash({ description: "choose1" })
23+
choose1(
24+
@SlashChoice({ name: "are you okay?", value: "okay" })
25+
@SlashChoice({ name: "are you good?", value: "good" })
26+
@SlashOption({
27+
description: "what1",
28+
name: "what1",
29+
required: true,
30+
type: ApplicationCommandOptionType.String,
31+
})
32+
what: string,
33+
interaction: CommandInteraction
34+
): void {
35+
interaction.reply(what);
36+
}
37+
}

src/commands/context.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type {
2+
MessageContextMenuCommandInteraction,
3+
UserContextMenuCommandInteraction,
4+
} from "discord.js";
5+
import { ApplicationCommandType } from "discord.js";
6+
import { ContextMenu, Discord } from "discordx";
7+
8+
@Discord()
9+
export class Example {
10+
@ContextMenu({
11+
name: "message context",
12+
type: ApplicationCommandType.Message,
13+
})
14+
messageHandler(interaction: MessageContextMenuCommandInteraction): void {
15+
interaction.reply("I am user context handler");
16+
}
17+
18+
@ContextMenu({ name: "user context", type: ApplicationCommandType.User })
19+
userHandler(interaction: UserContextMenuCommandInteraction): void {
20+
interaction.reply("I am user context handler");
21+
}
22+
}

src/commands/menu.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import type {
2+
CommandInteraction,
3+
MessageActionRowComponentBuilder,
4+
SelectMenuInteraction,
5+
} from "discord.js";
6+
import { ActionRowBuilder, SelectMenuBuilder } from "discord.js";
7+
import { Discord, SelectMenuComponent, Slash } from "discordx";
8+
9+
const roles = [
10+
{ label: "Principal", value: "principal" },
11+
{ label: "Teacher", value: "teacher" },
12+
{ label: "Student", value: "student" },
13+
];
14+
15+
@Discord()
16+
export class Example {
17+
@SelectMenuComponent({ id: "role-menu" })
18+
async handle(interaction: SelectMenuInteraction): Promise<unknown> {
19+
await interaction.deferReply();
20+
21+
// extract selected value by member
22+
const roleValue = interaction.values?.[0];
23+
24+
// if value not found
25+
if (!roleValue) {
26+
return interaction.followUp("invalid role id, select again");
27+
}
28+
29+
await interaction.followUp(
30+
`you have selected role: ${
31+
roles.find((r) => r.value === roleValue)?.label ?? "unknown"
32+
}`
33+
);
34+
return;
35+
}
36+
37+
@Slash({ description: "roles menu", name: "my_roles" })
38+
async myRoles(interaction: CommandInteraction): Promise<unknown> {
39+
await interaction.deferReply();
40+
41+
// create menu for roles
42+
const menu = new SelectMenuBuilder()
43+
.addOptions(roles)
44+
.setCustomId("role-menu");
45+
46+
// create a row for message actions
47+
const buttonRow =
48+
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
49+
menu
50+
);
51+
52+
// send it
53+
interaction.editReply({
54+
components: [buttonRow],
55+
content: "select your role!",
56+
});
57+
return;
58+
}
59+
}

src/commands/simple command.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { CommandInteraction, Message } from "discord.js";
2+
import type { SimpleCommandMessage } from "discordx";
3+
import {
4+
Discord,
5+
SimpleCommand,
6+
SimpleCommandOption,
7+
SimpleCommandOptionType,
8+
Slash,
9+
} from "discordx";
10+
11+
@Discord()
12+
export class Example {
13+
@SimpleCommand({ aliases: ["hi"] })
14+
hello(command: SimpleCommandMessage): void {
15+
command.message.reply(`👋 ${command.message.member}`);
16+
}
17+
18+
@SimpleCommand({ argSplitter: "+" })
19+
sum(
20+
@SimpleCommandOption({ name: "num1", type: SimpleCommandOptionType.Number })
21+
num1: number | undefined,
22+
@SimpleCommandOption({ name: "num2", type: SimpleCommandOptionType.Number })
23+
num2: number | undefined,
24+
command: SimpleCommandMessage
25+
): void {
26+
if (!num1 || !num2) {
27+
command.sendUsageSyntax();
28+
return;
29+
}
30+
command.message.reply(`total = ${num1 + num2}`);
31+
}
32+
33+
// make single handler for simple and slash command
34+
likeIt(command: CommandInteraction | Message): void {
35+
command.reply("I like it, Thanks");
36+
}
37+
38+
@SimpleCommand({ name: "like-it" })
39+
simpleLikeIt(command: SimpleCommandMessage): void {
40+
this.likeIt(command.message);
41+
}
42+
43+
@Slash({ description: "like-ite", name: "like-it" })
44+
slashLikeIt(command: CommandInteraction): void {
45+
this.likeIt(command);
46+
}
47+
}

0 commit comments

Comments
 (0)