@stonyx/discord 0.1.1-beta.43 → 0.1.1-beta.44

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 CHANGED
@@ -68,20 +68,13 @@ export default class MessageCreateHandler extends EventHandler {
68
68
 
69
69
  ### 4. Start the bot
70
70
 
71
- With Stonyx auto-initialization (recommended):
71
+ Stonyx auto-initializes the bot when your app boots — no manual wiring needed:
72
72
 
73
73
  ```bash
74
74
  stonyx serve
75
75
  ```
76
76
 
77
- Or manually:
78
-
79
- ```javascript
80
- import { DiscordBot } from '@stonyx/discord';
81
-
82
- const bot = new DiscordBot();
83
- await bot.init();
84
- ```
77
+ `Discord.init()` (called by the Stonyx module loader) awaits `new DiscordBot().init()`, which discovers commands/events, derives intents, and connects to the gateway. The lazy-init guards still apply: if `DISCORD_TOKEN` is unset or no commands/events exist, the bot skips login.
85
78
 
86
79
  ## Command Architecture
87
80
 
package/dist/bot.js CHANGED
@@ -17,9 +17,16 @@ export default class DiscordBot {
17
17
  DiscordBot.instance = this;
18
18
  }
19
19
  async init() {
20
+ if (this.client) {
21
+ // Already initialized — singleton reuse via Discord.init() or a direct
22
+ // new DiscordBot().init() call. Wait for the existing ready promise
23
+ // rather than re-running discovery + login.
24
+ await this.ready;
25
+ return;
26
+ }
20
27
  const { token } = config.discord;
21
28
  if (!token) {
22
- log.discord('No DISCORD_TOKEN configured — bot will not start');
29
+ log.discord?.('No DISCORD_TOKEN configured — bot will not start');
23
30
  this.resolveReady();
24
31
  return;
25
32
  }
@@ -27,7 +34,7 @@ export default class DiscordBot {
27
34
  await this.discoverEvents();
28
35
  const hasWork = Object.keys(this.commands).length > 0 || this.eventHandlers.length > 0;
29
36
  if (!hasWork) {
30
- log.discord('No discord commands or event handlers found — skipping bot initialization');
37
+ log.discord?.('No discord commands or event handlers found — skipping bot initialization');
31
38
  this.resolveReady();
32
39
  return;
33
40
  }
@@ -47,7 +54,7 @@ export default class DiscordBot {
47
54
  return;
48
55
  client.on('ready', () => {
49
56
  this.resolveReady();
50
- log.discord('Discord Bot is Ready!');
57
+ log.discord?.('Discord Bot is Ready!');
51
58
  });
52
59
  client.on('interactionCreate', async (interaction) => {
53
60
  if (!interaction.isChatInputCommand())
@@ -87,12 +94,12 @@ export default class DiscordBot {
87
94
  const CommandClass = CommandClassUntyped;
88
95
  const instance = new CommandClass();
89
96
  if (!instance.data || typeof instance.execute !== 'function') {
90
- log.discord(`Command "${name}" is missing data or execute — skipping`);
97
+ log.discord?.(`Command "${name}" is missing data or execute — skipping`);
91
98
  return;
92
99
  }
93
100
  instance._bot = this;
94
101
  this.commands[instance.data.name] = instance;
95
- log.discord(`Loaded command: /${instance.data.name}`);
102
+ log.discord?.(`Loaded command: /${instance.data.name}`);
96
103
  }, { ignoreAccessFailure: true });
97
104
  }
98
105
  async discoverEvents() {
@@ -102,13 +109,13 @@ export default class DiscordBot {
102
109
  await forEachFileImport(eventDir, (EventHandlerClassUntyped, { name }) => {
103
110
  const EventHandlerClass = EventHandlerClassUntyped;
104
111
  if (!EventHandlerClass.event) {
105
- log.discord(`Event handler "${name}" is missing static event property — skipping`);
112
+ log.discord?.(`Event handler "${name}" is missing static event property — skipping`);
106
113
  return;
107
114
  }
108
115
  const instance = new EventHandlerClass();
109
116
  instance._bot = this;
110
117
  this.eventHandlers.push(instance);
111
- log.discord(`Loaded event handler: ${EventHandlerClass.event} (${name})`);
118
+ log.discord?.(`Loaded event handler: ${EventHandlerClass.event} (${name})`);
112
119
  }, { ignoreAccessFailure: true });
113
120
  }
114
121
  async sendMessage(content, channelId, imagePath = null) {
package/dist/main.js CHANGED
@@ -1,3 +1,4 @@
1
+ import DiscordBot from './bot.js';
1
2
  export default class Discord {
2
3
  static instance;
3
4
  constructor() {
@@ -6,8 +7,7 @@ export default class Discord {
6
7
  Discord.instance = this;
7
8
  }
8
9
  async init() {
9
- // Bot initialization is deferred to DiscordBot.init()
10
- // This entry point satisfies Stonyx module auto-initialization
10
+ await new DiscordBot().init();
11
11
  }
12
12
  reset() {
13
13
  Discord.instance = null;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.1.1-beta.43",
7
+ "version": "0.1.1-beta.44",
8
8
  "description": "Discord bot module for the Stonyx framework",
9
9
  "main": "dist/main.js",
10
10
  "types": "dist/main.d.ts",