discord-bot-shared 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -0
- package/dist/guildCache.d.ts +7 -7
- package/dist/guildCache.js +2 -2
- package/dist/guildCache.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interactionCreate.js +1 -1
- package/dist/interactionCreate.js.map +1 -1
- package/dist/util.d.ts +4 -4
- package/dist/util.js +6 -7
- package/dist/util.js.map +1 -1
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -1 +1,153 @@
|
|
|
1
1
|
# discord-bot-shared
|
|
2
|
+
|
|
3
|
+
A module that makes creating discord.js bots a bit easier.
|
|
4
|
+
|
|
5
|
+
## Installation/Usage
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install discord-bot-shared
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- This module expects a `BOT_TOKEN` and `CLIENT_ID` environment variable to login.
|
|
12
|
+
- By default, commands are registered globally. To register commands to a specific guild, you can optionally provide `GUILD_ID`.
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
// index.ts
|
|
16
|
+
import login from 'discord-bot-shared'
|
|
17
|
+
import { ClientOptions, GatewayIntentBits as Intents, Partials } from 'discord.js'
|
|
18
|
+
|
|
19
|
+
const botIntents: ClientOptions = {
|
|
20
|
+
intents: [Intents.Guilds],
|
|
21
|
+
partials: [Partials.Reaction],
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const bot = await login(botIntents, import.meta.url)
|
|
25
|
+
|
|
26
|
+
export default bot
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**You must have a directory names `events` and `commands` next to your `index.ts` (or wherever you are importing `login()` from).**
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
.
|
|
33
|
+
└── src/
|
|
34
|
+
├── events/
|
|
35
|
+
│ └── someEvent.ts
|
|
36
|
+
├── commands/
|
|
37
|
+
│ └── someCommand.ts
|
|
38
|
+
└── index.ts
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Events
|
|
42
|
+
|
|
43
|
+
This module registers your bot's events by `import`ing each file under your `events` directory. Events are registered as a side-effect of the import.
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
// guildMemberAdd.ts
|
|
47
|
+
import bot from '../index.js'
|
|
48
|
+
|
|
49
|
+
bot.on('guildMemberAdd', (member) => {
|
|
50
|
+
// do stuff
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Commands
|
|
55
|
+
|
|
56
|
+
Your commands are registered by `import`ing the default export of each command file.
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
// myCommand.ts
|
|
60
|
+
import { Command } from 'discord-bot-shared'
|
|
61
|
+
import { SlashCommandBuilder } from 'discord.js'
|
|
62
|
+
|
|
63
|
+
const myCommand: Command = {
|
|
64
|
+
command: new SlashCommandBuilder()
|
|
65
|
+
.setName('my-command')
|
|
66
|
+
.setDescription('This command does stuff.') as SlashCommandBuilder,
|
|
67
|
+
run: (interaction) => {
|
|
68
|
+
// do stuff
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default myCommand
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Your `run` function is passed the command interaction that initiated the command.
|
|
76
|
+
|
|
77
|
+
### Exports
|
|
78
|
+
|
|
79
|
+
The following functions and interfaces/types are exported by this module:
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
#### `function login`
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
async function login(
|
|
87
|
+
botIntents: ClientOptions,
|
|
88
|
+
projectMetaURL: string,
|
|
89
|
+
interactionCheck?: InteractionCheck,
|
|
90
|
+
): Promise<Client>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- `botIntents` is a discord.js `ClientOptions` object.
|
|
94
|
+
- `projectMetaURL` should always be passed `import.meta.url`. This is used to find and register your events and commands.
|
|
95
|
+
- Optionally provide an `interactionCheck` function that returns a boolean. This function is called right before trying to run a command. The command will only run if `interactionCheck` returns true.
|
|
96
|
+
- The `InteractionCheck` type is also exported by this module.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
#### `function getGuildCache`
|
|
101
|
+
|
|
102
|
+
Returns an object that contains the guild and the following freshly fetched guild collections: `channels, emojis, members, roles`.
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
async function getGuildCache()
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- For example, a common pattern I use is something like this:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
const { members } = await getGuildCache()
|
|
112
|
+
// do stuff with members
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
#### `interface Command`
|
|
118
|
+
|
|
119
|
+
This interface defines the structure of your bot's commands. See above for an example of a command.
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
interface Command {
|
|
123
|
+
requiredRoles?: string[]
|
|
124
|
+
command: SlashCommandBuilder
|
|
125
|
+
run: (interaction: ChatInputCommandInteraction) => void | Promise<void>
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- Optionally provide `requiredRoles` string array. If the member initiating the command has _any_ of the roles provided in this array, they will be allowed to run the command.
|
|
130
|
+
- **You may have to type cast your command `as SlashCommandBuilder` due to the way discord.js' `SlashCommandBuilder` works.**
|
|
131
|
+
- `run` is the final function that will be called to run your command.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
#### `function getChannelByName`
|
|
136
|
+
|
|
137
|
+
Returns a guild channel of the given name and type, otherwise returns `undefined`.
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
async function getChannelByName<T extends NonThreadGuildBasedChannel>(
|
|
141
|
+
channelName: string,
|
|
142
|
+
channelType: NonThreadGuildBasedChannelType,
|
|
143
|
+
): Promise<T | undefined>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
- `T` can be one of `TextChannel | VoiceChannel | NewsChannel | StageChannel | CategoryChannel`.
|
|
147
|
+
- `channelType` is a discord.js `ChannelType`. Can be one of `GuildText | GuildVoice | GuildNews | GuildStageVoice | GuildCategory` (prepended with `ChannelType`).
|
|
148
|
+
- It is intended that you pass in a type for `T` that matches `channelType`. The returned channel is cast as whatever type is passed in.
|
|
149
|
+
- For example:
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
const someTextChannel = await getChannelByName<TextChannel>('some-text-channel', ChannelType.GuildText)
|
|
153
|
+
```
|
package/dist/guildCache.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Client
|
|
1
|
+
import { Client } from 'discord.js';
|
|
2
2
|
declare function setBot(botClient: Client): void;
|
|
3
|
-
declare function getGuildCache(
|
|
4
|
-
guild: Guild;
|
|
5
|
-
channels: import("
|
|
6
|
-
emojis: import("
|
|
7
|
-
members: import("
|
|
8
|
-
roles: import("
|
|
3
|
+
declare function getGuildCache(): Promise<{
|
|
4
|
+
guild: import("discord.js").Guild;
|
|
5
|
+
channels: import("discord.js").Collection<string, import("discord.js").NonThreadGuildBasedChannel>;
|
|
6
|
+
emojis: import("discord.js").Collection<string, import("discord.js").GuildEmoji>;
|
|
7
|
+
members: import("discord.js").Collection<string, import("discord.js").GuildMember>;
|
|
8
|
+
roles: import("discord.js").Collection<string, import("discord.js").Role>;
|
|
9
9
|
} | undefined>;
|
|
10
10
|
export default getGuildCache;
|
|
11
11
|
export { setBot };
|
package/dist/guildCache.js
CHANGED
|
@@ -2,13 +2,13 @@ let bot;
|
|
|
2
2
|
function setBot(botClient) {
|
|
3
3
|
bot = botClient;
|
|
4
4
|
}
|
|
5
|
-
async function getGuildCache(
|
|
5
|
+
async function getGuildCache() {
|
|
6
6
|
if (!bot)
|
|
7
7
|
return;
|
|
8
8
|
const guilds = await bot.guilds.fetch();
|
|
9
9
|
if (!guilds)
|
|
10
10
|
return;
|
|
11
|
-
const guild =
|
|
11
|
+
const guild = await guilds.first()?.fetch();
|
|
12
12
|
if (!guild)
|
|
13
13
|
return;
|
|
14
14
|
const channels = await guild.channels.fetch();
|
package/dist/guildCache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guildCache.js","sourceRoot":"","sources":["../src/guildCache.ts"],"names":[],"mappings":"AAEA,IAAI,GAAW,CAAA;AAEf,SAAS,MAAM,CAAC,SAAiB;IAC/B,GAAG,GAAG,SAAS,CAAA;AACjB,CAAC;AAED,KAAK,UAAU,aAAa
|
|
1
|
+
{"version":3,"file":"guildCache.js","sourceRoot":"","sources":["../src/guildCache.ts"],"names":[],"mappings":"AAEA,IAAI,GAAW,CAAA;AAEf,SAAS,MAAM,CAAC,SAAiB;IAC/B,GAAG,GAAG,SAAS,CAAA;AACjB,CAAC;AAED,KAAK,UAAU,aAAa;IAC1B,IAAI,CAAC,GAAG;QAAE,OAAM;IAEhB,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;IACvC,IAAI,CAAC,MAAM;QAAE,OAAM;IACnB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAA;IAC3C,IAAI,CAAC,KAAK;QAAE,OAAM;IAElB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IAC7C,IAAI,CAAC,QAAQ;QAAE,OAAM;IAErB,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;IACzC,IAAI,CAAC,MAAM;QAAE,OAAM;IAEnB,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IAC3C,IAAI,CAAC,OAAO;QAAE,OAAM;IAEpB,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACvC,IAAI,CAAC,KAAK;QAAE,OAAM;IAElB,OAAO;QACL,KAAK;QACL,QAAQ;QACR,MAAM;QACN,OAAO;QACP,KAAK;KACN,CAAA;AACH,CAAC;AAED,eAAe,aAAa,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export default login;
|
|
|
5
5
|
export { Command } from './commands.js';
|
|
6
6
|
export { default as getGuildCache } from './guildCache.js';
|
|
7
7
|
export { InteractionCheck } from './interactionCreate.js';
|
|
8
|
-
export {
|
|
8
|
+
export { getChannelByName, throwError } from './util.js';
|
package/dist/index.js
CHANGED
|
@@ -19,5 +19,5 @@ async function login(botIntents, projectMetaURL, interactionCheck) {
|
|
|
19
19
|
}
|
|
20
20
|
export default login;
|
|
21
21
|
export { default as getGuildCache } from './guildCache.js';
|
|
22
|
-
export {
|
|
22
|
+
export { getChannelByName, throwError } from './util.js';
|
|
23
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAA;AAClD,OAAO,gBAAgB,MAAM,eAAe,CAAA;AAC5C,OAAO,cAAc,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,yBAA+C,MAAM,wBAAwB,CAAA;AACpF,OAAO,aAAa,MAAM,YAAY,CAAA;AAEtC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAA;AAC5C,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAA;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,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,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -26,7 +26,7 @@ async function checkRoles(command, interaction) {
|
|
|
26
26
|
const member = await interaction.guild?.members.fetch(interaction.user).catch(console.error);
|
|
27
27
|
if (!member)
|
|
28
28
|
return;
|
|
29
|
-
return member.roles.cache.some((role) => command.requiredRoles ? command.requiredRoles.includes(role.name) : false);
|
|
29
|
+
return member.roles.cache.some((role) => (command.requiredRoles ? command.requiredRoles.includes(role.name) : false));
|
|
30
30
|
}
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactionCreate.js","sourceRoot":"","sources":["../src/interactionCreate.ts"],"names":[],"mappings":"AAKA,SAAS,yBAAyB,CAAC,GAAW,EAAE,QAA4B,EAAE,gBAAmC;IAC/G,GAAG,CAAC,EAAE,CAAC,mBAAmB,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE;QAChD,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE;YAAE,OAAM;QAE7C,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;QACrD,IAAI,CAAC,OAAO;YAAE,OAAO,gBAAgB,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAA;QAE5E,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YAC3C,OAAO,gBAAgB,CAAC,WAAW,EAAE,gEAAgE,CAAC,CAAA;QAExG,IAAI;YACF,MAAM,sBAAsB,GAAG,gBAAgB,CAAC,CAAC,CAAC,MAAM,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YAC5F,IAAI,CAAC,sBAAsB;gBAAE,OAAM;YAEnC,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;SAC/B;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAA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,CAAC,KAAK,WAAW,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AACxF,CAAC;AAED,eAAe,yBAAyB,CAAA"}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare
|
|
3
|
-
declare function
|
|
1
|
+
import { ChannelType, NonThreadGuildBasedChannel } from 'discord.js';
|
|
2
|
+
declare type NonThreadGuildBasedChannelType = ChannelType.GuildText | ChannelType.GuildVoice | ChannelType.GuildNews | ChannelType.GuildStageVoice | ChannelType.GuildCategory;
|
|
3
|
+
declare function getChannelByName<T extends NonThreadGuildBasedChannel>(channelName: string, channelType: NonThreadGuildBasedChannelType): Promise<T | undefined>;
|
|
4
4
|
declare function throwError(error: string): never;
|
|
5
|
-
export {
|
|
5
|
+
export { getChannelByName, throwError };
|
package/dist/util.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return channel.type === ChannelType.GuildCategory;
|
|
1
|
+
import getGuildCache from './guildCache.js';
|
|
2
|
+
async function getChannelByName(channelName, channelType) {
|
|
3
|
+
const { channels } = (await getGuildCache()) || throwError('Unable to get guild cache.');
|
|
4
|
+
const channel = channels.find((channel) => channel.name === channelName);
|
|
5
|
+
return channel && channel.type === channelType ? channel : undefined;
|
|
7
6
|
}
|
|
8
7
|
function throwError(error) {
|
|
9
8
|
throw new Error(error);
|
|
10
9
|
}
|
|
11
|
-
export {
|
|
10
|
+
export { getChannelByName, throwError };
|
|
12
11
|
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAS3C,KAAK,UAAU,gBAAgB,CAC7B,WAAmB,EACnB,WAA2C;IAE3C,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAC,MAAM,aAAa,EAAE,CAAC,IAAI,UAAU,CAAC,4BAA4B,CAAC,CAAA;IACxF,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAA;IAExE,OAAO,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAE,OAAa,CAAC,CAAC,CAAC,SAAS,CAAA;AAC7E,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "discord-bot-shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Modules for creating discord bots.",
|
|
6
6
|
"repository": "github:adamhl8/discord-bot-shared",
|
|
@@ -18,26 +18,26 @@
|
|
|
18
18
|
"lint": "eslint -f pretty --fix ."
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@discordjs/rest": "^1.0.
|
|
22
|
-
"discord-api-types": "^0.
|
|
23
|
-
"discord.js": "^14.0
|
|
21
|
+
"@discordjs/rest": "^1.0.1",
|
|
22
|
+
"discord-api-types": "^0.37.3",
|
|
23
|
+
"discord.js": "^14.2.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/eslint": "^8.4.
|
|
27
|
-
"@types/node": "^18.
|
|
28
|
-
"@types/prettier": "^2.
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
30
|
-
"@typescript-eslint/parser": "^5.
|
|
31
|
-
"eslint": "^8.
|
|
26
|
+
"@types/eslint": "^8.4.6",
|
|
27
|
+
"@types/node": "^18.7.9",
|
|
28
|
+
"@types/prettier": "^2.7.0",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
30
|
+
"@typescript-eslint/parser": "^5.33.1",
|
|
31
|
+
"eslint": "^8.22.0",
|
|
32
32
|
"eslint-config-prettier": "^8.5.0",
|
|
33
33
|
"eslint-formatter-pretty": "^4.1.0",
|
|
34
34
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
35
|
-
"eslint-plugin-sonarjs": "^0.
|
|
35
|
+
"eslint-plugin-sonarjs": "^0.15.0",
|
|
36
36
|
"eslint-plugin-unicorn": "^43.0.2",
|
|
37
37
|
"prettier": "^2.7.1",
|
|
38
|
-
"prettier-plugin-organize-imports": "^3.
|
|
39
|
-
"prettier-plugin-pkg": "^0.
|
|
40
|
-
"prettier-plugin-sh": "^0.12.
|
|
38
|
+
"prettier-plugin-organize-imports": "^3.1.0",
|
|
39
|
+
"prettier-plugin-pkg": "^0.17.0",
|
|
40
|
+
"prettier-plugin-sh": "^0.12.8",
|
|
41
41
|
"typescript": "^4.7.4"
|
|
42
42
|
}
|
|
43
43
|
}
|