Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mon4ik/discordjs-decorators
https://github.com/mon4ik/discordjs-decorators
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mon4ik/discordjs-decorators
- Owner: Mon4ik
- Created: 2023-06-16T14:16:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-17T07:40:24.000Z (over 1 year ago)
- Last Synced: 2024-04-23T13:54:46.546Z (7 months ago)
- Language: TypeScript
- Size: 28.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DiscordJS Decorators
DiscordJS decorators for better structure
![NPM](https://badgen.net/npm/v/@idkncc/discordjs-decorators)
![NPM](https://badgen.net/npm/dt/@idkncc/discordjs-decorators)## Installation
1. Install DiscordJS **(not next version!)**
```shell
yarn add discord.js
```
2. Install DiscordJS-Decorators
```shell
yarn add @idkncc/discordjs-decorators
```
3. Add to `tsconfig.json`
```json
"experimentalDecorators": true
```
4. Ready to use## Simplest Example
```ts
// index.ts
import {EventLoader, importGlob} from "@idkncc/discordjs-decorators";
import {Client, Events} from "discord.js";require("dotenv").config()
const client = new Client({intents: ["Guilds"]})
client.once(Events.ClientReady, c => {
console.log(`Bot is ready! Logged in as ${c.user.tag}`)new EventLoader()
// import whole folder
.add(importGlob("./events/**/*.ts"))// constants for command registering
.env(process.env.NODE_ENV !== "production", process.env.CLIENT_ID, process.env.GUILD_ID)// and finally load everything
.load(client)
})client.login(process.env.TOKEN)
``````ts
// /events/event.ts
import {Events} from "discord.js"
import {Event} from "@idkncc/discordjs-decorators"export class ExampleEventImportedOne {
// regular event
@Event(Events.MessageCreate)
messageCreate(d) {
console.log("Someone said")
}// register slashcommand
@SlashCommand.Name("warn")
@SlashCommand.Description("Warns user")
@SlashCommand.UserOption((opt) => opt
.setName("user")
.setDescription("User, who will get warned")
.setRequired(true)
)
@SlashCommand.StringOption((opt) => opt
.setName("reason")
.setDescription("Reason to warn")
)
testCommand(test: ChatInputCommandInteraction) {
// do smth
}
}
```Other example you can find in [`example/`](example/) folder
## TODO
- [ ] Validators **(very useful but not now :( )**
- [ ] More decorators for `@SlashCommand`
- [ ] Middlewares