@stonyx/discord 0.1.1-beta.13 → 0.1.1-beta.14

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.
Files changed (2) hide show
  1. package/dist/bot.js +15 -8
  2. package/package.json +1 -1
package/dist/bot.js CHANGED
@@ -31,9 +31,8 @@ export default class DiscordBot {
31
31
  this.resolveReady();
32
32
  return;
33
33
  }
34
- const discordConfig = config.discord;
35
- const intents = deriveIntents(this.eventHandlers, discordConfig.additionalIntents);
36
- const partials = derivePartials(intents, discordConfig.additionalPartials);
34
+ const intents = deriveIntents(this.eventHandlers, config.discord.additionalIntents);
35
+ const partials = derivePartials(intents, config.discord.additionalPartials);
37
36
  if (Object.keys(this.commands).length > 0) {
38
37
  intents.push(GatewayIntentBits.Guilds);
39
38
  }
@@ -113,6 +112,8 @@ export default class DiscordBot {
113
112
  }, { ignoreAccessFailure: true });
114
113
  }
115
114
  async sendMessage(content, channelId, imagePath = null) {
115
+ if (!this.client)
116
+ throw new Error('Discord bot is not initialized');
116
117
  const channel = await this.client.channels.fetch(channelId);
117
118
  if (!channel)
118
119
  throw new Error('Invalid Channel ID');
@@ -127,7 +128,7 @@ export default class DiscordBot {
127
128
  content: '',
128
129
  files: [{
129
130
  attachment: file,
130
- name: file.split('/').pop()
131
+ name: file.split('/').pop() ?? file
131
132
  }]
132
133
  });
133
134
  }
@@ -152,26 +153,32 @@ export default class DiscordBot {
152
153
  }
153
154
  }
154
155
  async updateStatus(name, type = 0) {
156
+ if (!this.client?.user)
157
+ throw new Error('Discord bot is not initialized');
155
158
  await this.client.user.setPresence({
156
159
  activities: [{ name, type }],
157
160
  status: 'online'
158
161
  });
159
162
  }
160
163
  async getChannelMessages(channelId, options = {}) {
164
+ if (!this.client)
165
+ throw new Error('Discord bot is not initialized');
161
166
  const channel = await this.client.channels.fetch(channelId);
162
- const discordConfig = config.discord;
163
167
  return await channel.messages.fetch({
164
- limit: discordConfig.maxMessagesPerRequest,
168
+ limit: config.discord.maxMessagesPerRequest,
165
169
  ...options
166
170
  });
167
171
  }
168
172
  async getChannelMessage(channelId, messageId) {
173
+ if (!this.client)
174
+ throw new Error('Discord bot is not initialized');
169
175
  const channel = await this.client.channels.fetch(channelId);
170
176
  return await channel.messages.fetch(messageId);
171
177
  }
172
178
  async getGuild(guildId) {
173
- const discordConfig = config.discord;
174
- return await this.client.guilds.fetch(guildId || discordConfig.serverId);
179
+ if (!this.client)
180
+ throw new Error('Discord bot is not initialized');
181
+ return await this.client.guilds.fetch(guildId || config.discord.serverId || '');
175
182
  }
176
183
  async clearChannelMessages(channelId) {
177
184
  const promises = [];
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.1.1-beta.13",
7
+ "version": "0.1.1-beta.14",
8
8
  "description": "Discord bot module for the Stonyx framework",
9
9
  "main": "dist/main.js",
10
10
  "types": "dist/main.d.ts",