discord-bot-shared 0.3.3 → 0.4.1
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 +34 -3
- package/dist/commands.d.ts +8 -8
- package/dist/commands.js +23 -24
- package/dist/events.d.ts +2 -2
- package/dist/events.js +10 -11
- package/dist/guildCache.d.ts +14 -11
- package/dist/guildCache.js +26 -33
- package/dist/guildCache.js.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +21 -21
- package/dist/index.js.map +1 -1
- package/dist/interactionCreate.d.ts +6 -6
- package/dist/interactionCreate.js +27 -33
- package/dist/interactionCreate.js.map +1 -1
- package/dist/ready.d.ts +3 -3
- package/dist/ready.js +5 -5
- package/dist/util.d.ts +15 -5
- package/dist/util.js +12 -6
- package/dist/util.js.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -78,6 +78,10 @@ Your `run` function is passed the command interaction that initiated the command
|
|
|
78
78
|
|
|
79
79
|
The following functions and interfaces/types are exported by this module:
|
|
80
80
|
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
#### `function login`
|
|
84
|
+
|
|
81
85
|
```
|
|
82
86
|
async function login(
|
|
83
87
|
botIntents: ClientOptions,
|
|
@@ -93,13 +97,14 @@ async function login(
|
|
|
93
97
|
|
|
94
98
|
---
|
|
95
99
|
|
|
100
|
+
#### `function getGuildCache`
|
|
101
|
+
|
|
96
102
|
Returns an object that contains the guild and the following freshly fetched guild collections: `channels, emojis, members, roles`.
|
|
97
103
|
|
|
98
104
|
```
|
|
99
|
-
async function getGuildCache(
|
|
105
|
+
async function getGuildCache()
|
|
100
106
|
```
|
|
101
107
|
|
|
102
|
-
- Optionally provide a Guild to retrieve the caches from. Otherwise, the first guild on the bot is used.
|
|
103
108
|
- For example, a common pattern I use is something like this:
|
|
104
109
|
|
|
105
110
|
```
|
|
@@ -109,6 +114,8 @@ const { members } = await getGuildCache()
|
|
|
109
114
|
|
|
110
115
|
---
|
|
111
116
|
|
|
117
|
+
#### `interface Command`
|
|
118
|
+
|
|
112
119
|
This interface defines the structure of your bot's commands. See above for an example of a command.
|
|
113
120
|
|
|
114
121
|
```
|
|
@@ -125,7 +132,31 @@ interface Command {
|
|
|
125
132
|
|
|
126
133
|
---
|
|
127
134
|
|
|
128
|
-
|
|
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
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
#### Channel Type Guards
|
|
158
|
+
|
|
159
|
+
These are channel type guards that you may need to use.
|
|
129
160
|
|
|
130
161
|
```
|
|
131
162
|
function isTextChannel(channel: BaseChannel | APIPartialChannel): channel is TextChannel
|
package/dist/commands.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ChatInputCommandInteraction, Collection, SlashCommandBuilder } from 'discord.js'
|
|
1
|
+
import { ChatInputCommandInteraction, Collection, SlashCommandBuilder } from 'discord.js'
|
|
2
2
|
interface Command {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
requiredRoles?: string[]
|
|
4
|
+
command: SlashCommandBuilder
|
|
5
|
+
run: (interaction: ChatInputCommandInteraction) => void | Promise<void>
|
|
6
6
|
}
|
|
7
|
-
declare type CommandsCollection = Collection<string, Command
|
|
8
|
-
declare function registerCommands(botToken: string, clientId: string, projectMetaURL: string, guildId?: string): Promise<CommandsCollection
|
|
9
|
-
export default registerCommands
|
|
10
|
-
export { Command, CommandsCollection }
|
|
7
|
+
declare type CommandsCollection = Collection<string, Command>
|
|
8
|
+
declare function registerCommands(botToken: string, clientId: string, projectMetaURL: string, guildId?: string): Promise<CommandsCollection>
|
|
9
|
+
export default registerCommands
|
|
10
|
+
export { Command, CommandsCollection }
|
package/dist/commands.js
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import { REST } from '@discordjs/rest'
|
|
2
|
-
import { Routes } from 'discord-api-types/v10'
|
|
3
|
-
import { Collection } from 'discord.js'
|
|
4
|
-
import { readdir } from 'node:fs/promises'
|
|
5
|
-
import { fileURLToPath } from 'node:url'
|
|
1
|
+
import { REST } from '@discordjs/rest'
|
|
2
|
+
import { Routes } from 'discord-api-types/v10'
|
|
3
|
+
import { Collection } from 'discord.js'
|
|
4
|
+
import { readdir } from 'node:fs/promises'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
6
|
async function registerCommands(botToken, clientId, projectMetaURL, guildId) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
guildId
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return commands;
|
|
7
|
+
const commands = new Collection()
|
|
8
|
+
const commandData = []
|
|
9
|
+
const commandsDirectory = fileURLToPath(new URL('commands', projectMetaURL))
|
|
10
|
+
const commandFiles = await readdir(commandsDirectory)
|
|
11
|
+
if (!commandFiles) return commands
|
|
12
|
+
for (const file of commandFiles) {
|
|
13
|
+
const { default: command } = await import(`${commandsDirectory}/${file}`)
|
|
14
|
+
commands.set(command.command.name, command)
|
|
15
|
+
commandData.push(command.command.toJSON())
|
|
16
|
+
}
|
|
17
|
+
const rest = new REST().setToken(botToken)
|
|
18
|
+
guildId
|
|
19
|
+
? await rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commandData })
|
|
20
|
+
: await rest.put(Routes.applicationCommands(clientId), { body: commandData })
|
|
21
|
+
console.log('Registered application (/) commands.')
|
|
22
|
+
return commands
|
|
24
23
|
}
|
|
25
|
-
export default registerCommands
|
|
26
|
-
//# sourceMappingURL=commands.js.map
|
|
24
|
+
export default registerCommands
|
|
25
|
+
//# sourceMappingURL=commands.js.map
|
package/dist/events.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function registerEvents(projectMetaURL: string): Promise<void
|
|
2
|
-
export default registerEvents
|
|
1
|
+
declare function registerEvents(projectMetaURL: string): Promise<void>
|
|
2
|
+
export default registerEvents
|
package/dist/events.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { readdir } from 'node:fs/promises'
|
|
2
|
-
import { fileURLToPath } from 'node:url'
|
|
1
|
+
import { readdir } from 'node:fs/promises'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
3
|
async function registerEvents(projectMetaURL) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
4
|
+
const eventsDirectory = fileURLToPath(new URL('events', projectMetaURL))
|
|
5
|
+
const eventFiles = await readdir(eventsDirectory).catch(console.error)
|
|
6
|
+
if (!eventFiles) return
|
|
7
|
+
for (const file of eventFiles) {
|
|
8
|
+
await import(`${eventsDirectory}/${file}`)
|
|
9
|
+
}
|
|
11
10
|
}
|
|
12
|
-
export default registerEvents
|
|
13
|
-
//# sourceMappingURL=events.js.map
|
|
11
|
+
export default registerEvents
|
|
12
|
+
//# sourceMappingURL=events.js.map
|
package/dist/guildCache.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Client
|
|
2
|
-
declare function setBot(botClient: Client): void
|
|
3
|
-
declare function getGuildCache(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { Client } from 'discord.js'
|
|
2
|
+
declare function setBot(botClient: Client): void
|
|
3
|
+
declare function getGuildCache(): Promise<
|
|
4
|
+
| {
|
|
5
|
+
guild: import('discord.js').Guild
|
|
6
|
+
channels: import('discord.js').Collection<string, import('discord.js').NonThreadGuildBasedChannel>
|
|
7
|
+
emojis: import('discord.js').Collection<string, import('discord.js').GuildEmoji>
|
|
8
|
+
members: import('discord.js').Collection<string, import('discord.js').GuildMember>
|
|
9
|
+
roles: import('discord.js').Collection<string, import('discord.js').Role>
|
|
10
|
+
}
|
|
11
|
+
| undefined
|
|
12
|
+
>
|
|
13
|
+
export default getGuildCache
|
|
14
|
+
export { setBot }
|
package/dist/guildCache.js
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
let bot
|
|
1
|
+
let bot
|
|
2
2
|
function setBot(botClient) {
|
|
3
|
-
|
|
3
|
+
bot = botClient
|
|
4
4
|
}
|
|
5
|
-
async function getGuildCache(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
guild,
|
|
28
|
-
channels,
|
|
29
|
-
emojis,
|
|
30
|
-
members,
|
|
31
|
-
roles,
|
|
32
|
-
};
|
|
5
|
+
async function getGuildCache() {
|
|
6
|
+
if (!bot) return
|
|
7
|
+
const guilds = await bot.guilds.fetch()
|
|
8
|
+
if (!guilds) return
|
|
9
|
+
const guild = await guilds.first()?.fetch()
|
|
10
|
+
if (!guild) return
|
|
11
|
+
const channels = await guild.channels.fetch()
|
|
12
|
+
if (!channels) return
|
|
13
|
+
const emojis = await guild.emojis.fetch()
|
|
14
|
+
if (!emojis) return
|
|
15
|
+
const members = await guild.members.fetch()
|
|
16
|
+
if (!members) return
|
|
17
|
+
const roles = await guild.roles.fetch()
|
|
18
|
+
if (!roles) return
|
|
19
|
+
return {
|
|
20
|
+
guild,
|
|
21
|
+
channels,
|
|
22
|
+
emojis,
|
|
23
|
+
members,
|
|
24
|
+
roles,
|
|
25
|
+
}
|
|
33
26
|
}
|
|
34
|
-
export default getGuildCache
|
|
35
|
-
export { setBot }
|
|
36
|
-
//# sourceMappingURL=guildCache.js.map
|
|
27
|
+
export default getGuildCache
|
|
28
|
+
export { setBot }
|
|
29
|
+
//# sourceMappingURL=guildCache.js.map
|
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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Client, ClientOptions } from 'discord.js'
|
|
2
|
-
import { InteractionCheck } from './interactionCreate.js'
|
|
3
|
-
declare function login(botIntents: ClientOptions, projectMetaURL: string, interactionCheck?: InteractionCheck): Promise<Client
|
|
4
|
-
export default login
|
|
5
|
-
export { Command } from './commands.js'
|
|
6
|
-
export { default as getGuildCache } from './guildCache.js'
|
|
7
|
-
export { InteractionCheck } from './interactionCreate.js'
|
|
8
|
-
export { isCategoryChannel, isTextChannel, throwError } from './util.js'
|
|
1
|
+
import { Client, ClientOptions } from 'discord.js'
|
|
2
|
+
import { InteractionCheck } from './interactionCreate.js'
|
|
3
|
+
declare function login(botIntents: ClientOptions, projectMetaURL: string, interactionCheck?: InteractionCheck): Promise<Client>
|
|
4
|
+
export default login
|
|
5
|
+
export { Command } from './commands.js'
|
|
6
|
+
export { default as getGuildCache } from './guildCache.js'
|
|
7
|
+
export { InteractionCheck } from './interactionCreate.js'
|
|
8
|
+
export { getChannelByName, isCategoryChannel, isTextChannel, throwError } from './util.js'
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { Client } from 'discord.js'
|
|
2
|
-
import registerCommands from './commands.js'
|
|
3
|
-
import registerEvents from './events.js'
|
|
4
|
-
import { setBot } from './guildCache.js'
|
|
5
|
-
import registerInteractionCreate from './interactionCreate.js'
|
|
6
|
-
import registerReady from './ready.js'
|
|
7
|
-
const botToken = process.env.BOT_TOKEN || ''
|
|
8
|
-
const clientId = process.env.CLIENT_ID || ''
|
|
9
|
-
const guildId = process.env.GUILD_ID || ''
|
|
1
|
+
import { Client } from 'discord.js'
|
|
2
|
+
import registerCommands from './commands.js'
|
|
3
|
+
import registerEvents from './events.js'
|
|
4
|
+
import { setBot } from './guildCache.js'
|
|
5
|
+
import registerInteractionCreate from './interactionCreate.js'
|
|
6
|
+
import registerReady from './ready.js'
|
|
7
|
+
const botToken = process.env.BOT_TOKEN || ''
|
|
8
|
+
const clientId = process.env.CLIENT_ID || ''
|
|
9
|
+
const guildId = process.env.GUILD_ID || ''
|
|
10
10
|
async function login(botIntents, projectMetaURL, interactionCheck) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
const bot = new Client(botIntents)
|
|
12
|
+
const commands = await registerCommands(botToken, clientId, projectMetaURL, guildId)
|
|
13
|
+
registerReady(bot)
|
|
14
|
+
registerInteractionCreate(bot, commands, interactionCheck)
|
|
15
|
+
void registerEvents(projectMetaURL)
|
|
16
|
+
setBot(bot)
|
|
17
|
+
void bot.login(botToken)
|
|
18
|
+
return bot
|
|
19
19
|
}
|
|
20
|
-
export default login
|
|
21
|
-
export { default as getGuildCache } from './guildCache.js'
|
|
22
|
-
export { isCategoryChannel, isTextChannel, throwError } from './util.js'
|
|
23
|
-
//# sourceMappingURL=index.js.map
|
|
20
|
+
export default login
|
|
21
|
+
export { default as getGuildCache } from './guildCache.js'
|
|
22
|
+
export { getChannelByName, isCategoryChannel, isTextChannel, throwError } from './util.js'
|
|
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,CAAC,QAAQ,IAAI,EAAE,CAAA;AAE1C,KAAK,UAAU,KAAK,
|
|
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,CAAC,QAAQ,IAAI,EAAE,CAAA;AAE1C,KAAK,UAAU,KAAK,CAAC,UAAyB,EAAE,cAAsB,EAAE,gBAAmC;IACzG,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAA;IAClC,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,CAAC,CAAA;IAEpF,aAAa,CAAC,GAAG,CAAC,CAAA;IAClB,yBAAyB,CAAC,GAAG,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAA;IAC1D,KAAK,cAAc,CAAC,cAAc,CAAC,CAAA;IAEnC,MAAM,CAAC,GAAG,CAAC,CAAA;IAEX,KAAK,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACxB,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,eAAe,KAAK,CAAA;AAEpB,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE1D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ChatInputCommandInteraction, Client } from 'discord.js'
|
|
2
|
-
import { CommandsCollection } from './commands.js'
|
|
3
|
-
declare type InteractionCheck = (interaction: ChatInputCommandInteraction) => Promise<boolean | void
|
|
4
|
-
declare function registerInteractionCreate(bot: Client, commands: CommandsCollection, interactionCheck?: InteractionCheck): void
|
|
5
|
-
export default registerInteractionCreate
|
|
6
|
-
export { InteractionCheck }
|
|
1
|
+
import { ChatInputCommandInteraction, Client } from 'discord.js'
|
|
2
|
+
import { CommandsCollection } from './commands.js'
|
|
3
|
+
declare type InteractionCheck = (interaction: ChatInputCommandInteraction) => Promise<boolean | void>
|
|
4
|
+
declare function registerInteractionCreate(bot: Client, commands: CommandsCollection, interactionCheck?: InteractionCheck): void
|
|
5
|
+
export default registerInteractionCreate
|
|
6
|
+
export { InteractionCheck }
|
|
@@ -1,39 +1,33 @@
|
|
|
1
1
|
function registerInteractionCreate(bot, commands, interactionCheck) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const errorMessage = error instanceof Error ? error.message : '';
|
|
18
|
-
interactionReply(interaction, `There was an error while running this command.\n${errorMessage}`);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
2
|
+
bot.on('interactionCreate', async (interaction) => {
|
|
3
|
+
if (!interaction.isChatInputCommand()) return
|
|
4
|
+
const command = commands.get(interaction.commandName)
|
|
5
|
+
if (!command) return interactionReply(interaction, 'Unable to get command.')
|
|
6
|
+
if (!(await checkRoles(command, interaction)))
|
|
7
|
+
return interactionReply(interaction, 'You do not have one of the required roles to run this command.')
|
|
8
|
+
try {
|
|
9
|
+
const interactionCheckPassed = interactionCheck ? await interactionCheck(interaction) : true
|
|
10
|
+
if (!interactionCheckPassed) return
|
|
11
|
+
await command.run(interaction)
|
|
12
|
+
} catch (error) {
|
|
13
|
+
const errorMessage = error instanceof Error ? error.message : ''
|
|
14
|
+
interactionReply(interaction, `There was an error while running this command.\n${errorMessage}`)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
21
17
|
}
|
|
22
18
|
async function checkRoles(command, interaction) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
19
|
+
if (!command.requiredRoles) return true
|
|
20
|
+
if (command.requiredRoles.length > 0) {
|
|
21
|
+
const member = await interaction.guild?.members.fetch(interaction.user).catch(console.error)
|
|
22
|
+
if (!member) return
|
|
23
|
+
return member.roles.cache.some((role) => (command.requiredRoles ? command.requiredRoles.includes(role.name) : false))
|
|
24
|
+
}
|
|
25
|
+
return false
|
|
32
26
|
}
|
|
33
27
|
function interactionReply(interaction, message) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
interaction.deferred
|
|
29
|
+
? void interaction.editReply(message).catch(console.error)
|
|
30
|
+
: void interaction.reply({ content: message, ephemeral: true }).catch(console.error)
|
|
37
31
|
}
|
|
38
|
-
export default registerInteractionCreate
|
|
39
|
-
//# sourceMappingURL=interactionCreate.js.map
|
|
32
|
+
export default registerInteractionCreate
|
|
33
|
+
//# sourceMappingURL=interactionCreate.js.map
|
|
@@ -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,CAA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AA;AACd,CAAC;AAED,SAAS,gBAAgB,CAAC,WAAwC,EAAE,OAAe;IACjF,WAAW,CAAC,QAAQ;QAClB,CAAC,CAAC,KAAK,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1D,CAAC,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/ready.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Client } from 'discord.js'
|
|
2
|
-
declare function registerReady(bot: Client): void
|
|
3
|
-
export default registerReady
|
|
1
|
+
import { Client } from 'discord.js'
|
|
2
|
+
declare function registerReady(bot: Client): void
|
|
3
|
+
export default registerReady
|
package/dist/ready.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function registerReady(bot) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
bot.once('ready', () => {
|
|
3
|
+
console.log('I am ready!')
|
|
4
|
+
})
|
|
5
5
|
}
|
|
6
|
-
export default registerReady
|
|
7
|
-
//# sourceMappingURL=ready.js.map
|
|
6
|
+
export default registerReady
|
|
7
|
+
//# sourceMappingURL=ready.js.map
|
package/dist/util.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import { APIPartialChannel, BaseChannel, CategoryChannel, TextChannel } from 'discord.js'
|
|
2
|
-
declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { APIPartialChannel, BaseChannel, CategoryChannel, ChannelType, NonThreadGuildBasedChannel, TextChannel } from 'discord.js'
|
|
2
|
+
declare type NonThreadGuildBasedChannelType =
|
|
3
|
+
| ChannelType.GuildText
|
|
4
|
+
| ChannelType.GuildVoice
|
|
5
|
+
| ChannelType.GuildNews
|
|
6
|
+
| ChannelType.GuildStageVoice
|
|
7
|
+
| ChannelType.GuildCategory
|
|
8
|
+
declare function getChannelByName<T extends NonThreadGuildBasedChannel>(
|
|
9
|
+
channelName: string,
|
|
10
|
+
channelType: NonThreadGuildBasedChannelType,
|
|
11
|
+
): Promise<T | undefined>
|
|
12
|
+
declare function isTextChannel(channel: BaseChannel | APIPartialChannel): channel is TextChannel
|
|
13
|
+
declare function isCategoryChannel(channel: BaseChannel): channel is CategoryChannel
|
|
14
|
+
declare function throwError(error: string): never
|
|
15
|
+
export { getChannelByName, isTextChannel, isCategoryChannel, throwError }
|
package/dist/util.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { ChannelType } from 'discord.js'
|
|
1
|
+
import { ChannelType } from 'discord.js'
|
|
2
|
+
import getGuildCache from './guildCache.js'
|
|
3
|
+
async function getChannelByName(channelName, channelType) {
|
|
4
|
+
const { channels } = (await getGuildCache()) || throwError('Unable to get guild cache.')
|
|
5
|
+
const channel = channels.find((channel) => channel.name === channelName)
|
|
6
|
+
return channel && channel.type === channelType ? channel : undefined
|
|
7
|
+
}
|
|
2
8
|
function isTextChannel(channel) {
|
|
3
|
-
|
|
9
|
+
return channel.type === ChannelType.GuildText
|
|
4
10
|
}
|
|
5
11
|
function isCategoryChannel(channel) {
|
|
6
|
-
|
|
12
|
+
return channel.type === ChannelType.GuildCategory
|
|
7
13
|
}
|
|
8
14
|
function throwError(error) {
|
|
9
|
-
|
|
15
|
+
throw new Error(error)
|
|
10
16
|
}
|
|
11
|
-
export { isTextChannel, isCategoryChannel, throwError }
|
|
12
|
-
//# sourceMappingURL=util.js.map
|
|
17
|
+
export { getChannelByName, isTextChannel, isCategoryChannel, throwError }
|
|
18
|
+
//# 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":"AAAA,OAAO,EAAmD,WAAW,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmD,WAAW,EAA2C,MAAM,YAAY,CAAA;AAClI,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,aAAa,CAAC,OAAwC;IAC7D,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,SAAS,CAAA;AAC/C,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAoB;IAC7C,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,aAAa,CAAA;AACnD,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,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.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Modules for creating discord bots.",
|
|
6
6
|
"repository": "github:adamhl8/discord-bot-shared",
|
|
@@ -19,24 +19,24 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@discordjs/rest": "^1.0.1",
|
|
22
|
-
"discord-api-types": "^0.37.
|
|
23
|
-
"discord.js": "^14.
|
|
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.
|
|
26
|
+
"@types/eslint": "^8.4.6",
|
|
27
|
+
"@types/node": "^18.7.9",
|
|
28
28
|
"@types/prettier": "^2.7.0",
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "^5.33.
|
|
30
|
-
"@typescript-eslint/parser": "^5.33.
|
|
31
|
-
"eslint": "^8.
|
|
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
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.0
|
|
39
|
-
"prettier-plugin-pkg": "^0.
|
|
38
|
+
"prettier-plugin-organize-imports": "^3.1.0",
|
|
39
|
+
"prettier-plugin-pkg": "^0.17.0",
|
|
40
40
|
"prettier-plugin-sh": "^0.12.8",
|
|
41
41
|
"typescript": "^4.7.4"
|
|
42
42
|
}
|