Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Fixes and New Features #62

Closed
wants to merge 106 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
8937987
### fix
Jul 1, 2021
c0b39d7
fix github.com/OwenCalvin/discord.ts/pull/56
Jul 1, 2021
a9ad6ee
fix github.com/OwenCalvin/discord.ts/pull/58
Jul 1, 2021
2138b4f
fix github.com/OwenCalvin/discord.ts/pull/60
Jul 1, 2021
9906e10
unused var and decorator fix
Jul 1, 2021
d66fc71
fix https://discord.js.org/#/docs/main/master/class/ApplicationComma…
Jul 1, 2021
4815968
fix no-inferrable-types
Jul 1, 2021
5762d9a
fix type error
Jul 1, 2021
d02a953
## init slash for guilds
Jul 1, 2021
d87ebba
multiple bot support
Jul 1, 2021
029539b
fix github.com/OwenCalvin/discord.ts/issues/49
Jul 1, 2021
d5bf0df
multi bot support
Jul 1, 2021
841d506
fix multiple bot
Jul 1, 2021
26ae1b7
readme
Jul 1, 2021
2e5cb5c
original readme restored
Jul 1, 2021
2b5ab41
fixes based on @AndyClausen suggestion
Jul 1, 2021
0558c4a
* formated code with prettier
Jul 1, 2021
0587f80
strong type checking
Jul 1, 2021
a0aad89
fix empty constructor
Jul 1, 2021
f73bd73
DGroup type fix
Jul 1, 2021
56cf961
ModifyFunction from it's usage
Jul 1, 2021
dcb582b
Client type fix
Jul 2, 2021
6479166
classes code fix
Jul 2, 2021
c234eea
initslash fix
Jul 2, 2021
f81c2c1
multibot events support fix
Jul 2, 2021
7314985
adde log options for initslash
Jul 2, 2021
c43d6c0
init slash fix
Jul 2, 2021
f4ab388
execute slash fix
Jul 2, 2021
3474122
init slash fix
Jul 2, 2021
6a27fd3
* test update
Jul 2, 2021
ee9f472
* recoded classes again
Jul 2, 2021
f3cb42b
jest test passed
Jul 2, 2021
0d01296
multiple bot support fix for groups
Jul 2, 2021
547a04b
added ``Bot()`` decorator
Jul 2, 2021
8d2edfa
fix multiple bot for groups
Jul 2, 2021
805f909
* new featured added: buttons selectmenu
Jul 3, 2021
899551d
fix button/selectmenu
Jul 3, 2021
78d4a4a
Update button not found log
vijayymmeena Jul 3, 2021
82d60ae
Update menu not found log text
vijayymmeena Jul 3, 2021
ad599cd
fix init slash with permissions
Jul 3, 2021
86773fd
fix permissions on init slash
Jul 3, 2021
82e122c
permissions global comment
Jul 3, 2021
ec69d24
removed unwanted permission code
Jul 3, 2021
64d386e
fixed examples to support latest code
Jul 3, 2021
49fe6e9
update executeInteraction
Jul 3, 2021
721e7fe
doc update bot multiple botid
Jul 3, 2021
ac44935
accepted pull OwenCalvin/discord.ts/pull/56
Jul 3, 2021
1d1c3e7
added button example
Jul 3, 2021
df83522
fix example button
Jul 3, 2021
8c5fca1
added menu example
Jul 3, 2021
60d8759
update
Jul 3, 2021
16fd3e0
restored important async on decorators
Jul 3, 2021
fb9866a
* jest test failed because of buttons
Jul 3, 2021
53017f6
jest test fix for slash commands
Jul 3, 2021
932dea0
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
2b59105
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
680ad51
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
816b652
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
8b346ae
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
92da21f
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
2411836
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
f84dfbb
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
5a1a6aa
fix button example
Jul 3, 2021
fa563e7
requiredByDefault set back to false
Jul 3, 2021
3514725
doc update: botid required, classes not required
Jul 3, 2021
6929eec
doc update: MetadataStorage
Jul 3, 2021
79b85cc
doc update
Jul 3, 2021
f770a2e
doc: added incomplete notes
Jul 3, 2021
659ef2f
doc: warning for incomplete docs
Jul 3, 2021
0c911f6
example update: function rename
Jul 4, 2021
55e1367
updated deprecated events
Jul 4, 2021
5c88ad9
added unknown interaction warning
Jul 4, 2021
42652d2
removed unwanted filter
Jul 4, 2021
61ecc3a
gourp permission fix
Jul 4, 2021
445b82e
update: permission decorator
Jul 4, 2021
c283fbb
developer can set default permission for slash
Jul 4, 2021
5c39108
removed unwanted greater than condition
Jul 4, 2021
a105dc5
* new decorator @DefaultPermission
Jul 4, 2021
a195d2c
doc for @DefaultPermission
Jul 4, 2021
65af9b4
init slash > guild > replace for loop with foreach
Jul 4, 2021
85b28a4
init slash > guild > replaced for loop
Jul 4, 2021
1824aca
@Bot fix for @On
Jul 4, 2021
947a0ef
botid fix for events
Jul 4, 2021
3a787fd
comment update for initslash
Jul 5, 2021
a06d222
solution for multiple class import
Jul 5, 2021
d837639
revert back last commit
Jul 5, 2021
3b7acda
fix multiple imports under multiple clients
Jul 5, 2021
a7587f4
removed unused variable
Jul 5, 2021
d8ab4f9
regular update based on discord.js
Jul 5, 2021
60f4008
jest slash test fix
Jul 5, 2021
f301739
simple command support
Jul 6, 2021
3f9ddd3
fix examples
Jul 6, 2021
1c8ff7a
fixed event execute
Jul 6, 2021
dcdab5d
simple command example
Jul 6, 2021
9d5bd0e
update command example
Jul 6, 2021
d04e31a
fix ``@Commad`` executation
Jul 6, 2021
ae2b055
update example command
Jul 6, 2021
2eb57d0
example command update
Jul 6, 2021
01fa0bb
update executecommand
Jul 6, 2021
1916229
fix permissions decorator for commands
Jul 6, 2021
b01b90d
update commands private to public for external use
Jul 6, 2021
6215c2a
guard type update
Jul 7, 2021
a741e2d
type fix
Jul 7, 2021
fe33ac7
doc formated
Jul 7, 2021
bb30bb8
guard example update
Jul 7, 2021
150a239
update guard example
Jul 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"rules": {
"semi": "error",
"quotes": "error",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
"@typescript-eslint/no-non-null-assertion": "off"
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": "off"
}
}
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
</p>

# 🎻 Introduction

This module is an extension of **[discord.**js**](https://discordjs.guide/)**, so the internal behavior (methods, properties, ...) is the same.

This library allows you to use TypeScript decorators on discord.**js**, it simplify your code and improve the readability !

# 📜 Documentation

**[https://owencalvin.github.io/discord.ts/](https://owencalvin.github.io/discord.ts/)**

# 📟 @Slash - Discord commands

Discord has it's own command system now, you can simply declare commands and use Slash commands this way

```ts
Expand All @@ -46,7 +49,9 @@ abstract class AppDiscord {
```

## Decorators related to Slash commands

There is a whole system that allows you to implement complex Slash commands

- `@Choice`
- `@Choices`
- `@Option`
Expand All @@ -57,9 +62,10 @@ There is a whole system that allows you to implement complex Slash commands
- `@Guard`

# 💡@On / @Once - Discord events
We can declare methods that will be executed whenever a Discord event is triggered.

Our methods must be decorated with the `@On(event: string)` or `@Once(event: string)` decorator.
We can declare methods that will be executed whenever a Discord event is triggered.

Our methods must be decorated with the `@On(event: string)` or `@Once(event: string)` decorator.

That's simple, when the event is triggered, the method is called:

Expand All @@ -68,7 +74,7 @@ import { Discord, On, Once } from "@typeit/discord";

@Discord()
abstract class AppDiscord {
@On("message")
@On("messageCreate")
private onMessage() {
// ...
}
Expand All @@ -81,6 +87,7 @@ abstract class AppDiscord {
```

# ⚔️ Guards

We implemented a guard system thats work pretty like the [Koa](https://koajs.com/) middleware system

You can use functions that are executed before your event to determine if it's executed. For example, if you want to apply a prefix to the messages, you can simply use the `@Guard` decorator.
Expand All @@ -96,12 +103,12 @@ import { Prefix } from "./Prefix";

@Discord()
abstract class AppDiscord {
@On("message")
@On("messageCreate")
@Guard(
NotBot, // You can use multiple guard functions, they are excuted in the same order!
Prefix("!")
)
async onMessage([message]: ArgsOf<"message">) {
async onMessage([message]: ArgsOf<"messageCreate">) {
switch (message.content.toLowerCase()) {
case "hello":
message.reply("Hello!");
Expand All @@ -115,13 +122,13 @@ abstract class AppDiscord {
```

# 📡 Installation

Use [npm](https://www.npmjs.com/package/@typeit/discord) or yarn to install **@typeit/discord@slash** with **discord.js**

**[Please refer to the documentation](https://owencalvin.github.io/discord.ts/installation/#installation)**


# ☎️ Need help?

**[Simply join the Discord server](https://discord.gg/VDjwu8E)**
**[Simply join the Discord server](https://discord.gg/VDjwu8E)**

You can also find help with the [different projects that use discord.ts](https://github.com/OwenCalvin/discord.ts/network/dependents?package_id=UGFja2FnZS00Njc1MzYwNzU%3D) and in the [examples folder](https://github.com/OwenCalvin/discord.ts/tree/master/examples)
18 changes: 11 additions & 7 deletions docs/src/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,21 @@ module.exports = {
path: "/decorators/discord",
children: [
["/decorators/discord", "@Discord"],
["/decorators/on", "@On"],
["/decorators/once", "@Once"],
["/decorators/slash", "@Slash"],
["/decorators/option", "@Option"],
["/decorators/bot", "@Bot"],
["/decorators/button", "@Button"],
["/decorators/choice", "@Choice"],
["/decorators/choices", "@Choices"],
["/decorators/guild", "@Guild"],
["/decorators/permission", "@Permission"],
["/decorators/description", "@Description"],
["/decorators/group", "@Group"],
["/decorators/guard", "@Guard"],
["/decorators/description", "@Description"],
["/decorators/guild", "@Guild"],
["/decorators/on", "@On"],
["/decorators/once", "@Once"],
["/decorators/option", "@Option"],
["/decorators/defaultpermission", "@DefaultPermission"],
["/decorators/permission", "@Permission"],
["/decorators/selectmenu", "@SelectMenu"],
["/decorators/slash", "@Slash"],
]
}
]
Expand Down
5 changes: 5 additions & 0 deletions docs/src/decorators/bot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @Bot

::: danger
doc for `@Bot` is not ready
:::
5 changes: 5 additions & 0 deletions docs/src/decorators/button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @Button

::: danger
doc for `@Button` is not ready
:::
7 changes: 6 additions & 1 deletion docs/src/decorators/choice.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# @Choice

An option of a Slash command can implement an autocompletion feature for `string` and `number` types

![](/discord.ts/choices.png)

## Setup autocompletion
You just decorate your parameter with one or multiple @Choice !

You just decorate your parameter with one or multiple @Choice !

```ts
@Discord()
Expand All @@ -25,12 +27,15 @@ class DiscordBot {
```

## Params

`@Choice(name: string, value: string | number)`

### Name

`string`
You have to set a diplayed name for your Choice

### Value

`string | number`
You have to set a value for your choice, if the user select "Astraunot", you will receive the value "astro"
3 changes: 2 additions & 1 deletion docs/src/decorators/choices.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# @Choices

It works exactly like [@Choice](/decorators/choice/) except that you can directly pass an object or enum to define all the choices at once

> The key of the object or enum is what discord shows and the value is the property value (object[key])
Expand All @@ -7,7 +8,7 @@ It works exactly like [@Choice](/decorators/choice/) except that you can directl
enum TextChoices {
// WhatDiscordShows = value
Hello = "Hello",
"Good Bye" = "GoodBye"
"Good Bye" = "GoodBye",
}

// Could be
Expand Down
5 changes: 5 additions & 0 deletions docs/src/decorators/defaultpermission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @DefaultPermission

::: danger
doc for `@DefaultPermission` is not ready
:::
5 changes: 3 additions & 2 deletions docs/src/decorators/description.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# @Description

This decorator is a shortcut to set the description property

```typescript
import { ClassCommand, Command, CommandMessage } from "@typeit/discord";
import { CommandInteraction } from "discord.js"
import { CommandInteraction } from "discord.js";

@Discord()
export abstract class DiscordBot {
Expand All @@ -19,7 +20,7 @@ Is equivalent to:

```typescript
import { ClassCommand, Command, CommandMessage } from "@typeit/discord";
import { CommandInteraction } from "discord.js"
import { CommandInteraction } from "discord.js";

@Discord()
export abstract class DiscordBot {
Expand Down
8 changes: 4 additions & 4 deletions docs/src/decorators/discord.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# @Discord

This decorator instanciate the class inside the discord.**ts** library to access to the class members or to call the methods

::: danger
Expand All @@ -11,10 +12,9 @@ import { Discord, Slash } from "@typeit/discord";
@Discord()
abstract class AppDiscord {
// We can use member decorators
// because we decorated the class with @Discord
@Slash("hello")
private hello(
) {
// because we decorated the class with @Discord
@Slash("hello")
private hello() {
// ...
}
}
Expand Down
31 changes: 17 additions & 14 deletions docs/src/decorators/group.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @Group

You can group your command like this

```
command
|
Expand All @@ -8,6 +10,7 @@ command
|__ subcommand

```

```
command
|
Expand All @@ -21,17 +24,21 @@ command
```

## Example
Here you create a Slash command group that groups "permissions" commands

Here you create a Slash command group that groups "permissions" commands

The permissions commands also grouped by "user" or "role"

![](https://discord.com/assets/4cfea1bfc6d3ed0396c16cd47e0a7154.png)

## Create a Group

We use @Group at two level, on the class and on methods

### Group on class level

When @Group decorate a class it groups all the Slash commands in the class

```
maths
|
Expand All @@ -42,10 +49,7 @@ maths

```ts
@Discord()
@Group(
"maths",
"maths group description",
)
@Group("maths", "maths group description")
export abstract class AppDiscord {
@Slash("add")
add(
Expand All @@ -70,12 +74,15 @@ export abstract class AppDiscord {
}
}
```

![](/discord.ts/group1.png)

### Group on method level

When @Group decorate a method it creates sub-groups inside the class group

**You have to list the groups that are in the class in the @Group parameters that decorate the class, or they will not appear**

```ts
@Group(
"testing",
Expand All @@ -102,16 +109,13 @@ testing
|
|__ root
```

```ts
@Discord()
@Group(
"testing",
"Testing group description",
{
maths: "maths group description",
text: "text group description"
}
)
@Group("testing", "Testing group description", {
maths: "maths group description",
text: "text group description",
})
export abstract class AppDiscord {
@Slash("add")
@Group("maths")
Expand Down Expand Up @@ -155,4 +159,3 @@ export abstract class AppDiscord {
```

![](/discord.ts/group2.png)

Loading