@elizaos/plugin-discord 1.0.9 → 1.0.11

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/dist/index.js CHANGED
@@ -652,7 +652,6 @@ ${attachments}`;
652
652
  let currentSummary = "";
653
653
  const chunkSize = 8e3;
654
654
  const chunks = await splitChunks(formattedMemories, chunkSize, 0);
655
- const _datestr = (/* @__PURE__ */ new Date()).toUTCString().replace(/:/g, "-");
656
655
  state.values.memoriesWithAttachments = formattedMemories;
657
656
  state.values.objective = objective;
658
657
  for (let i = 0; i < chunks.length; i++) {
@@ -925,11 +924,11 @@ var transcribeMedia = {
925
924
  return;
926
925
  }
927
926
  const mediaTranscript = attachment.text;
928
- callbackData.text = mediaTranscript.trim();
927
+ callbackData.text = mediaTranscript?.trim();
929
928
  if (callbackData.text && (callbackData.text?.split("\n").length < 4 || callbackData.text?.split(" ").length < 100)) {
930
929
  callbackData.text = `Here is the transcript:
931
930
  \`\`\`md
932
- ${mediaTranscript.trim()}
931
+ ${mediaTranscript?.trim()}
933
932
  \`\`\`
934
933
  `;
935
934
  await callback(callbackData);
@@ -987,7 +986,7 @@ import {
987
986
  ChannelType as ChannelType2,
988
987
  ModelType as ModelType5,
989
988
  composePromptFromState as composePromptFromState5,
990
- createUniqueUuid as createUniqueUuid2,
989
+ createUniqueUuid,
991
990
  logger
992
991
  } from "@elizaos/core";
993
992
  import {
@@ -1063,7 +1062,7 @@ var joinVoice = {
1063
1062
  const guild = client.guilds.cache.get(serverId);
1064
1063
  const members = guild?.members.cache;
1065
1064
  const member = members?.find(
1066
- (member2) => createUniqueUuid2(runtime, member2.id) === message.entityId
1065
+ (member2) => createUniqueUuid(runtime, member2.id) === message.entityId
1067
1066
  );
1068
1067
  if (member?.voice?.channel) {
1069
1068
  const userVoiceChannel = member.voice.channel;
@@ -1088,7 +1087,7 @@ var joinVoice = {
1088
1087
  {
1089
1088
  entityId: message.entityId,
1090
1089
  agentId: message.agentId,
1091
- roomId: createUniqueUuid2(runtime, userVoiceChannel.id),
1090
+ roomId: createUniqueUuid(runtime, userVoiceChannel.id),
1092
1091
  content: {
1093
1092
  source: "discord",
1094
1093
  thought: `I joined the voice channel ${userVoiceChannel.name}`,
@@ -1153,7 +1152,7 @@ You should only respond with the name of the voice channel or none, no commentar
1153
1152
  {
1154
1153
  entityId: message.entityId,
1155
1154
  agentId: message.agentId,
1156
- roomId: createUniqueUuid2(runtime, targetChannel2.id),
1155
+ roomId: createUniqueUuid(runtime, targetChannel2.id),
1157
1156
  content: {
1158
1157
  source: "discord",
1159
1158
  thought: `I joined the voice channel ${targetChannel2.name}`,
@@ -1301,7 +1300,7 @@ You should only respond with the name of the voice channel or none, no commentar
1301
1300
  // src/actions/voiceLeave.ts
1302
1301
  import {
1303
1302
  ChannelType as ChannelType3,
1304
- createUniqueUuid as createUniqueUuid3,
1303
+ createUniqueUuid as createUniqueUuid2,
1305
1304
  logger as logger2
1306
1305
  } from "@elizaos/core";
1307
1306
  import { BaseGuildVoiceChannel } from "discord.js";
@@ -1320,7 +1319,7 @@ var leaveVoice = {
1320
1319
  return false;
1321
1320
  }
1322
1321
  const service = runtime.getService(ServiceType2.DISCORD);
1323
- if (!service) {
1322
+ if (!service || !service.client) {
1324
1323
  logger2.error("Discord client not found");
1325
1324
  return false;
1326
1325
  }
@@ -1328,7 +1327,7 @@ var leaveVoice = {
1328
1327
  if (room?.type !== ChannelType3.GROUP && room?.type !== ChannelType3.VOICE_GROUP) {
1329
1328
  return false;
1330
1329
  }
1331
- const isConnectedToVoice = service.client.voice.adapters.size > 0;
1330
+ const isConnectedToVoice = (service.client?.voice.adapters.size || 0) > 0;
1332
1331
  return isConnectedToVoice;
1333
1332
  },
1334
1333
  description: "Leave the current voice channel.",
@@ -1425,7 +1424,7 @@ var leaveVoice = {
1425
1424
  {
1426
1425
  entityId: message.entityId,
1427
1426
  agentId: message.agentId,
1428
- roomId: createUniqueUuid3(runtime, voiceChannel.id),
1427
+ roomId: createUniqueUuid2(runtime, voiceChannel.id),
1429
1428
  content: {
1430
1429
  source: "discord",
1431
1430
  thought: `I left the voice channel ${voiceChannel.name}`,
@@ -1764,7 +1763,7 @@ import {
1764
1763
  EventType as EventType2,
1765
1764
  Role,
1766
1765
  Service,
1767
- createUniqueUuid as createUniqueUuid6,
1766
+ createUniqueUuid as createUniqueUuid5,
1768
1767
  logger as logger6
1769
1768
  } from "@elizaos/core";
1770
1769
  import {
@@ -1795,7 +1794,7 @@ import {
1795
1794
  ChannelType as ChannelType7,
1796
1795
  EventType,
1797
1796
  ServiceType as ServiceType4,
1798
- createUniqueUuid as createUniqueUuid4,
1797
+ createUniqueUuid as createUniqueUuid3,
1799
1798
  logger as logger4
1800
1799
  } from "@elizaos/core";
1801
1800
  import {
@@ -2391,11 +2390,11 @@ var MessageManager = class {
2391
2390
  if (this.runtime.character.settings?.discord?.shouldRespondOnlyToMentions && (!this.client.user?.id || !message.mentions.users?.has(this.client.user.id))) {
2392
2391
  return;
2393
2392
  }
2394
- const entityId = createUniqueUuid4(this.runtime, message.author.id);
2393
+ const entityId = createUniqueUuid3(this.runtime, message.author.id);
2395
2394
  const userName = message.author.bot ? `${message.author.username}#${message.author.discriminator}` : message.author.username;
2396
2395
  const name = message.author.displayName;
2397
2396
  const channelId = message.channel.id;
2398
- const roomId = createUniqueUuid4(this.runtime, channelId);
2397
+ const roomId = createUniqueUuid3(this.runtime, channelId);
2399
2398
  let type;
2400
2399
  let serverId;
2401
2400
  if (message.guild) {
@@ -2407,7 +2406,7 @@ var MessageManager = class {
2407
2406
  serverId = guild.id;
2408
2407
  } else {
2409
2408
  type = ChannelType7.DM;
2410
- serverId = void 0;
2409
+ serverId = message.channel.id;
2411
2410
  }
2412
2411
  await this.runtime.ensureConnection({
2413
2412
  entityId,
@@ -2418,7 +2417,7 @@ var MessageManager = class {
2418
2417
  channelId: message.channel.id,
2419
2418
  serverId,
2420
2419
  type,
2421
- worldId: createUniqueUuid4(this.runtime, serverId ?? roomId),
2420
+ worldId: createUniqueUuid3(this.runtime, serverId ?? roomId),
2422
2421
  worldName: message.guild?.name
2423
2422
  });
2424
2423
  try {
@@ -2440,8 +2439,8 @@ var MessageManager = class {
2440
2439
  if (!processedContent && !attachments?.length) {
2441
2440
  return;
2442
2441
  }
2443
- const entityId2 = createUniqueUuid4(this.runtime, message.author.id);
2444
- const messageId = createUniqueUuid4(this.runtime, message.id);
2442
+ const entityId2 = createUniqueUuid3(this.runtime, message.author.id);
2443
+ const messageId = createUniqueUuid3(this.runtime, message.id);
2445
2444
  const channel = message.channel;
2446
2445
  const startTyping = () => {
2447
2446
  try {
@@ -2459,7 +2458,7 @@ var MessageManager = class {
2459
2458
  startTyping();
2460
2459
  const typingInterval = setInterval(startTyping, 8e3);
2461
2460
  typingData.interval = typingInterval;
2462
- await new Promise((resolve) => setTimeout(resolve, 200));
2461
+ const sourceId = createUniqueUuid3(this.runtime, message.author.id);
2463
2462
  const newMessage = {
2464
2463
  id: messageId,
2465
2464
  entityId: entityId2,
@@ -2473,27 +2472,38 @@ var MessageManager = class {
2473
2472
  source: "discord",
2474
2473
  channelType: type,
2475
2474
  url: message.url,
2476
- inReplyTo: message.reference?.messageId ? createUniqueUuid4(this.runtime, message.reference?.messageId) : void 0
2475
+ inReplyTo: message.reference?.messageId ? createUniqueUuid3(this.runtime, message.reference?.messageId) : void 0
2477
2476
  },
2478
2477
  // metadata of memory
2479
2478
  metadata: {
2480
2479
  entityName: name,
2480
+ fromBot: message.author.bot,
2481
2481
  // include very technical/exact reference to this user for security reasons
2482
2482
  // don't remove or change this, spartan needs this
2483
2483
  fromId: message.author.id,
2484
+ // do we need to duplicate this, we have it in content
2485
+ // source: "discord",
2486
+ sourceId,
2484
2487
  // why message? all Memories contain content (which is basically a message)
2485
- // what are the other types?
2488
+ // what are the other types? see MemoryType
2486
2489
  type: "message"
2490
+ // MemoryType.MESSAGE
2491
+ // scope: `shared`, `private`, or `room
2492
+ // timestamp
2493
+ // tags
2487
2494
  },
2488
2495
  createdAt: message.createdTimestamp
2489
2496
  };
2490
2497
  const callback = async (content, files) => {
2491
2498
  try {
2499
+ if (content.target && content.target.toLowerCase() !== "discord") {
2500
+ return;
2501
+ }
2492
2502
  if (message.id && !content.inReplyTo) {
2493
- content.inReplyTo = createUniqueUuid4(this.runtime, message.id);
2503
+ content.inReplyTo = createUniqueUuid3(this.runtime, message.id);
2494
2504
  }
2495
2505
  let messages = [];
2496
- if (content?.source === "DM") {
2506
+ if (content?.channelType === "DM") {
2497
2507
  const u = await this.client.users.fetch(message.author.id);
2498
2508
  if (!u) {
2499
2509
  logger4.warn("Discord - User not found", message.author.id);
@@ -2513,7 +2523,7 @@ var MessageManager = class {
2513
2523
  for (const m of messages) {
2514
2524
  const actions = content.actions;
2515
2525
  const memory = {
2516
- id: createUniqueUuid4(this.runtime, m.id),
2526
+ id: createUniqueUuid3(this.runtime, m.id),
2517
2527
  entityId: this.runtime.agentId,
2518
2528
  agentId: this.runtime.agentId,
2519
2529
  content: {
@@ -2683,7 +2693,7 @@ import {
2683
2693
  import {
2684
2694
  ChannelType as ChannelType8,
2685
2695
  ModelType as ModelType8,
2686
- createUniqueUuid as createUniqueUuid5,
2696
+ createUniqueUuid as createUniqueUuid4,
2687
2697
  logger as logger5
2688
2698
  } from "@elizaos/core";
2689
2699
  import {
@@ -3328,8 +3338,8 @@ var VoiceManager = class extends EventEmitter {
3328
3338
  if (!message || message.trim() === "" || message.length < 3) {
3329
3339
  return { text: "", actions: ["IGNORE"] };
3330
3340
  }
3331
- const roomId = createUniqueUuid5(this.runtime, channelId);
3332
- const uniqueEntityId = createUniqueUuid5(this.runtime, entityId);
3341
+ const roomId = createUniqueUuid4(this.runtime, channelId);
3342
+ const uniqueEntityId = createUniqueUuid4(this.runtime, entityId);
3333
3343
  const type = await this.getChannelType(channel);
3334
3344
  await this.runtime.ensureConnection({
3335
3345
  entityId: uniqueEntityId,
@@ -3340,11 +3350,11 @@ var VoiceManager = class extends EventEmitter {
3340
3350
  channelId,
3341
3351
  serverId: channel.guild.id,
3342
3352
  type,
3343
- worldId: createUniqueUuid5(this.runtime, channel.guild.id),
3353
+ worldId: createUniqueUuid4(this.runtime, channel.guild.id),
3344
3354
  worldName: channel.guild.name
3345
3355
  });
3346
3356
  const memory = {
3347
- id: createUniqueUuid5(
3357
+ id: createUniqueUuid4(
3348
3358
  this.runtime,
3349
3359
  `${channelId}-voice-message-${Date.now()}`
3350
3360
  ),
@@ -3365,7 +3375,7 @@ var VoiceManager = class extends EventEmitter {
3365
3375
  const callback = async (content, _files = []) => {
3366
3376
  try {
3367
3377
  const responseMemory = {
3368
- id: createUniqueUuid5(
3378
+ id: createUniqueUuid4(
3369
3379
  this.runtime,
3370
3380
  `${memory.id}-voice-response-${Date.now()}`
3371
3381
  ),
@@ -3602,9 +3612,7 @@ var DiscordService = class _DiscordService extends Service {
3602
3612
  }
3603
3613
  const token = runtime.getSetting("DISCORD_API_TOKEN");
3604
3614
  if (!token || token.trim() === "") {
3605
- logger6.warn(
3606
- "Discord API Token not provided - Discord functionality will be unavailable"
3607
- );
3615
+ runtime.logger.warn("Discord API Token not provided - Discord functionality will be unavailable");
3608
3616
  this.client = null;
3609
3617
  return;
3610
3618
  }
@@ -3634,7 +3642,7 @@ var DiscordService = class _DiscordService extends Service {
3634
3642
  this.messageManager = new MessageManager(this);
3635
3643
  this.client.once(Events.ClientReady, this.onReady.bind(this));
3636
3644
  this.client.login(token).catch((error) => {
3637
- logger6.error(
3645
+ runtime.logger.error(
3638
3646
  `Failed to login to Discord: ${error instanceof Error ? error.message : String(error)}`
3639
3647
  );
3640
3648
  this.client = null;
@@ -3642,7 +3650,7 @@ var DiscordService = class _DiscordService extends Service {
3642
3650
  this.setupEventListeners();
3643
3651
  this.registerSendHandler();
3644
3652
  } catch (error) {
3645
- logger6.error(
3653
+ runtime.logger.error(
3646
3654
  `Error initializing Discord client: ${error instanceof Error ? error.message : String(error)}`
3647
3655
  );
3648
3656
  this.client = null;
@@ -3674,11 +3682,11 @@ var DiscordService = class _DiscordService extends Service {
3674
3682
  */
3675
3683
  async handleSendMessage(runtime, target, content) {
3676
3684
  if (!this.client?.isReady()) {
3677
- logger6.error("[Discord SendHandler] Client not ready.");
3685
+ runtime.logger.error("[Discord SendHandler] Client not ready.");
3678
3686
  throw new Error("Discord client is not ready.");
3679
3687
  }
3680
3688
  if (target.channelId && this.allowedChannelIds && !this.allowedChannelIds.includes(target.channelId)) {
3681
- logger6.warn(
3689
+ runtime.logger.warn(
3682
3690
  `[Discord SendHandler] Channel ${target.channelId} is not in allowed channels, skipping send.`
3683
3691
  );
3684
3692
  return;
@@ -3709,7 +3717,7 @@ var DiscordService = class _DiscordService extends Service {
3709
3717
  await targetChannel.send(chunk);
3710
3718
  }
3711
3719
  } else {
3712
- logger6.warn(
3720
+ runtime.logger.warn(
3713
3721
  "[Discord SendHandler] No text content provided to send."
3714
3722
  );
3715
3723
  }
@@ -3724,7 +3732,7 @@ var DiscordService = class _DiscordService extends Service {
3724
3732
  );
3725
3733
  }
3726
3734
  } catch (error) {
3727
- logger6.error(
3735
+ runtime.logger.error(
3728
3736
  `[Discord SendHandler] Error sending message: ${error instanceof Error ? error.message : String(error)}`,
3729
3737
  {
3730
3738
  target,
@@ -3803,7 +3811,7 @@ var DiscordService = class _DiscordService extends Service {
3803
3811
  try {
3804
3812
  this.messageManager?.handleMessage(message);
3805
3813
  } catch (error) {
3806
- logger6.error(`Error handling message: ${error}`);
3814
+ this.runtime.logger.error(`Error handling message: ${error}`);
3807
3815
  }
3808
3816
  });
3809
3817
  this.client.on("messageReactionAdd", async (reaction, user) => {
@@ -3816,7 +3824,7 @@ var DiscordService = class _DiscordService extends Service {
3816
3824
  try {
3817
3825
  await this.handleReactionAdd(reaction, user);
3818
3826
  } catch (error) {
3819
- logger6.error(`Error handling reaction add: ${error}`);
3827
+ this.runtime.logger.error(`Error handling reaction add: ${error}`);
3820
3828
  }
3821
3829
  });
3822
3830
  this.client.on("messageReactionRemove", async (reaction, user) => {
@@ -3829,21 +3837,21 @@ var DiscordService = class _DiscordService extends Service {
3829
3837
  try {
3830
3838
  await this.handleReactionRemove(reaction, user);
3831
3839
  } catch (error) {
3832
- logger6.error(`Error handling reaction remove: ${error}`);
3840
+ this.runtime.logger.error(`Error handling reaction remove: ${error}`);
3833
3841
  }
3834
3842
  });
3835
3843
  this.client.on("guildCreate", async (guild) => {
3836
3844
  try {
3837
3845
  await this.handleGuildCreate(guild);
3838
3846
  } catch (error) {
3839
- logger6.error(`Error handling guild create: ${error}`);
3847
+ this.runtime.logger.error(`Error handling guild create: ${error}`);
3840
3848
  }
3841
3849
  });
3842
3850
  this.client.on("guildMemberAdd", async (member) => {
3843
3851
  try {
3844
3852
  await this.handleGuildMemberAdd(member);
3845
3853
  } catch (error) {
3846
- logger6.error(`Error handling guild member add: ${error}`);
3854
+ this.runtime.logger.error(`Error handling guild member add: ${error}`);
3847
3855
  }
3848
3856
  });
3849
3857
  this.client.on("interactionCreate", async (interaction) => {
@@ -3853,12 +3861,13 @@ var DiscordService = class _DiscordService extends Service {
3853
3861
  try {
3854
3862
  await this.handleInteractionCreate(interaction);
3855
3863
  } catch (error) {
3856
- logger6.error(`Error handling interaction: ${error}`);
3864
+ this.runtime.logger.error(`Error handling interaction: ${error}`);
3857
3865
  }
3858
3866
  });
3859
3867
  this.client.on(
3860
3868
  "userStream",
3861
3869
  (entityId, name, userName, channel, opusDecoder) => {
3870
+ console.log("userStream", entityId, name, userName, channel.id);
3862
3871
  if (entityId !== this.client?.user?.id) {
3863
3872
  this.voiceManager?.handleUserStream(
3864
3873
  entityId,
@@ -3879,11 +3888,11 @@ var DiscordService = class _DiscordService extends Service {
3879
3888
  * @private
3880
3889
  */
3881
3890
  async handleGuildMemberAdd(member) {
3882
- logger6.log(`New member joined: ${member.user.username}`);
3891
+ this.runtime.logger.log(`New member joined: ${member.user.username}`);
3883
3892
  const guild = member.guild;
3884
3893
  const tag = member.user.bot ? `${member.user.username}#${member.user.discriminator}` : member.user.username;
3885
- const worldId = createUniqueUuid6(this.runtime, guild.id);
3886
- const entityId = createUniqueUuid6(this.runtime, member.id);
3894
+ const worldId = createUniqueUuid5(this.runtime, guild.id);
3895
+ const entityId = createUniqueUuid5(this.runtime, member.id);
3887
3896
  this.runtime.emitEvent([EventType2.ENTITY_JOINED], {
3888
3897
  runtime: this.runtime,
3889
3898
  entityId,
@@ -3912,11 +3921,11 @@ var DiscordService = class _DiscordService extends Service {
3912
3921
  * @private
3913
3922
  */
3914
3923
  async handleGuildCreate(guild) {
3915
- logger6.log(`Joined guild ${guild.name}`);
3924
+ this.runtime.logger.log(`Joined guild ${guild.name}`);
3916
3925
  const fullGuild = await guild.fetch();
3917
3926
  this.voiceManager?.scanGuild(guild);
3918
- const ownerId = createUniqueUuid6(this.runtime, fullGuild.ownerId);
3919
- const worldId = createUniqueUuid6(this.runtime, fullGuild.id);
3927
+ const ownerId = createUniqueUuid5(this.runtime, fullGuild.ownerId);
3928
+ const worldId = createUniqueUuid5(this.runtime, fullGuild.id);
3920
3929
  const standardizedData = {
3921
3930
  runtime: this.runtime,
3922
3931
  rooms: await this.buildStandardizedRooms(fullGuild, worldId),
@@ -3960,7 +3969,7 @@ var DiscordService = class _DiscordService extends Service {
3960
3969
  }
3961
3970
  }
3962
3971
  if (interaction.isMessageComponent()) {
3963
- logger6.info(`Received component interaction: ${interaction.customId}`);
3972
+ this.runtime.logger.info(`Received component interaction: ${interaction.customId}`);
3964
3973
  const userId = interaction.user?.id;
3965
3974
  const messageId = interaction.message?.id;
3966
3975
  if (!this.userSelections.has(userId)) {
@@ -3968,33 +3977,33 @@ var DiscordService = class _DiscordService extends Service {
3968
3977
  }
3969
3978
  const userSelections = this.userSelections.get(userId);
3970
3979
  if (!userSelections) {
3971
- logger6.error(
3980
+ this.runtime.logger.error(
3972
3981
  `User selections map unexpectedly missing for user ${userId}`
3973
3982
  );
3974
3983
  return;
3975
3984
  }
3976
3985
  try {
3977
3986
  if (interaction.isStringSelectMenu()) {
3978
- logger6.info(`Values selected: ${JSON.stringify(interaction.values)}`);
3979
- logger6.info(
3987
+ this.runtime.logger.info(`Values selected: ${JSON.stringify(interaction.values)}`);
3988
+ this.runtime.logger.info(
3980
3989
  `User ${userId} selected values for ${interaction.customId}: ${JSON.stringify(interaction.values)}`
3981
3990
  );
3982
3991
  userSelections[messageId] = {
3983
3992
  ...userSelections[messageId],
3984
3993
  [interaction.customId]: interaction.values
3985
3994
  };
3986
- logger6.info(
3995
+ this.runtime.logger.info(
3987
3996
  `Current selections for message ${messageId}: ${JSON.stringify(userSelections[messageId])}`
3988
3997
  );
3989
3998
  await interaction.deferUpdate();
3990
3999
  }
3991
4000
  if (interaction.isButton()) {
3992
- logger6.info("Button interaction detected");
3993
- logger6.info(
4001
+ this.runtime.logger.info("Button interaction detected");
4002
+ this.runtime.logger.info(
3994
4003
  `Button pressed by user ${userId}: ${interaction.customId}`
3995
4004
  );
3996
4005
  const formSelections = userSelections[messageId] || {};
3997
- logger6.info(
4006
+ this.runtime.logger.info(
3998
4007
  `Form data being submitted: ${JSON.stringify(formSelections)}`
3999
4008
  );
4000
4009
  this.runtime.emitEvent(["DISCORD_INTERACTION"], {
@@ -4009,7 +4018,7 @@ var DiscordService = class _DiscordService extends Service {
4009
4018
  source: "discord"
4010
4019
  });
4011
4020
  delete userSelections[messageId];
4012
- logger6.info(`Cleared selections for message ${messageId}`);
4021
+ this.runtime.logger.info(`Cleared selections for message ${messageId}`);
4013
4022
  await interaction.deferUpdate();
4014
4023
  await interaction.followUp({
4015
4024
  content: "Form submitted successfully!",
@@ -4017,14 +4026,14 @@ var DiscordService = class _DiscordService extends Service {
4017
4026
  });
4018
4027
  }
4019
4028
  } catch (error) {
4020
- logger6.error(`Error handling component interaction: ${error}`);
4029
+ this.runtime.logger.error(`Error handling component interaction: ${error}`);
4021
4030
  try {
4022
4031
  await interaction.followUp({
4023
4032
  content: "There was an error processing your interaction.",
4024
4033
  ephemeral: true
4025
4034
  });
4026
4035
  } catch (followUpError) {
4027
- logger6.error(`Error sending follow-up message: ${followUpError}`);
4036
+ this.runtime.logger.error(`Error sending follow-up message: ${followUpError}`);
4028
4037
  }
4029
4038
  }
4030
4039
  }
@@ -4041,7 +4050,7 @@ var DiscordService = class _DiscordService extends Service {
4041
4050
  const rooms = [];
4042
4051
  for (const [channelId, channel] of guild.channels.cache) {
4043
4052
  if (channel.type === DiscordChannelType4.GuildText || channel.type === DiscordChannelType4.GuildVoice) {
4044
- const roomId = createUniqueUuid6(this.runtime, channelId);
4053
+ const roomId = createUniqueUuid5(this.runtime, channelId);
4045
4054
  let channelType;
4046
4055
  switch (channel.type) {
4047
4056
  case DiscordChannelType4.GuildText:
@@ -4058,9 +4067,9 @@ var DiscordService = class _DiscordService extends Service {
4058
4067
  try {
4059
4068
  participants = Array.from(guild.members.cache.values()).filter(
4060
4069
  (member) => channel.permissionsFor(member)?.has(PermissionsBitField2.Flags.ViewChannel)
4061
- ).map((member) => createUniqueUuid6(this.runtime, member.id));
4070
+ ).map((member) => createUniqueUuid5(this.runtime, member.id));
4062
4071
  } catch (error) {
4063
- logger6.warn(
4072
+ this.runtime.logger.warn(
4064
4073
  `Failed to get participants for channel ${channel.name}:`,
4065
4074
  error
4066
4075
  );
@@ -4089,15 +4098,15 @@ var DiscordService = class _DiscordService extends Service {
4089
4098
  const entities = [];
4090
4099
  const botId = this.client?.user?.id;
4091
4100
  if (guild.memberCount > 1e3) {
4092
- logger6.info(
4093
- `Using optimized user sync for large guild ${guild.name} (${guild.memberCount} members)`
4101
+ this.runtime.logger.info(
4102
+ `Using optimized user sync for large guild ${guild.name} (${guild.memberCount.toLocaleString()} members)`
4094
4103
  );
4095
4104
  try {
4096
4105
  for (const [, member] of guild.members.cache) {
4097
4106
  const tag = member.user.bot ? `${member.user.username}#${member.user.discriminator}` : member.user.username;
4098
4107
  if (member.id !== botId) {
4099
4108
  entities.push({
4100
- id: createUniqueUuid6(this.runtime, member.id),
4109
+ id: createUniqueUuid5(this.runtime, member.id),
4101
4110
  names: Array.from(
4102
4111
  new Set(
4103
4112
  [
@@ -4128,11 +4137,11 @@ var DiscordService = class _DiscordService extends Service {
4128
4137
  }
4129
4138
  }
4130
4139
  if (entities.length < 100) {
4131
- logger6.info(`Adding online members for ${guild.name}`);
4140
+ this.runtime.logger.info(`Adding online members for ${guild.name}`);
4132
4141
  const onlineMembers = await guild.members.fetch({ limit: 100 });
4133
4142
  for (const [, member] of onlineMembers) {
4134
4143
  if (member.id !== botId) {
4135
- const entityId = createUniqueUuid6(this.runtime, member.id);
4144
+ const entityId = createUniqueUuid5(this.runtime, member.id);
4136
4145
  if (!entities.some((u) => u.id === entityId)) {
4137
4146
  const tag = member.user.bot ? `${member.user.username}#${member.user.discriminator}` : member.user.username;
4138
4147
  entities.push({
@@ -4169,7 +4178,7 @@ var DiscordService = class _DiscordService extends Service {
4169
4178
  }
4170
4179
  }
4171
4180
  } catch (error) {
4172
- logger6.error(`Error fetching members for ${guild.name}:`, error);
4181
+ this.runtime.logger.error(`Error fetching members for ${guild.name}:`, error);
4173
4182
  }
4174
4183
  } else {
4175
4184
  try {
@@ -4181,7 +4190,7 @@ var DiscordService = class _DiscordService extends Service {
4181
4190
  if (member.id !== botId) {
4182
4191
  const tag = member.user.bot ? `${member.user.username}#${member.user.discriminator}` : member.user.username;
4183
4192
  entities.push({
4184
- id: createUniqueUuid6(this.runtime, member.id),
4193
+ id: createUniqueUuid5(this.runtime, member.id),
4185
4194
  names: Array.from(
4186
4195
  new Set(
4187
4196
  [
@@ -4212,7 +4221,7 @@ var DiscordService = class _DiscordService extends Service {
4212
4221
  }
4213
4222
  }
4214
4223
  } catch (error) {
4215
- logger6.error(`Error fetching members for ${guild.name}:`, error);
4224
+ this.runtime.logger.error(`Error fetching members for ${guild.name}:`, error);
4216
4225
  }
4217
4226
  }
4218
4227
  return entities;
@@ -4223,11 +4232,36 @@ var DiscordService = class _DiscordService extends Service {
4223
4232
  * @private
4224
4233
  * @returns {Promise<void>} A promise that resolves when all on-ready tasks are completed.
4225
4234
  */
4226
- async onReady() {
4227
- logger6.log("DISCORD ON READY");
4235
+ async onReady(readyClient) {
4236
+ this.runtime.logger.success("DISCORD ON READY");
4237
+ const requiredPermissions = [
4238
+ // Text Permissions
4239
+ PermissionsBitField2.Flags.ViewChannel,
4240
+ PermissionsBitField2.Flags.SendMessages,
4241
+ PermissionsBitField2.Flags.SendMessagesInThreads,
4242
+ PermissionsBitField2.Flags.CreatePrivateThreads,
4243
+ PermissionsBitField2.Flags.CreatePublicThreads,
4244
+ PermissionsBitField2.Flags.EmbedLinks,
4245
+ PermissionsBitField2.Flags.AttachFiles,
4246
+ PermissionsBitField2.Flags.AddReactions,
4247
+ PermissionsBitField2.Flags.UseExternalEmojis,
4248
+ PermissionsBitField2.Flags.UseExternalStickers,
4249
+ PermissionsBitField2.Flags.MentionEveryone,
4250
+ PermissionsBitField2.Flags.ManageMessages,
4251
+ PermissionsBitField2.Flags.ReadMessageHistory,
4252
+ // Voice Permissions
4253
+ PermissionsBitField2.Flags.Connect,
4254
+ PermissionsBitField2.Flags.Speak,
4255
+ PermissionsBitField2.Flags.UseVAD,
4256
+ PermissionsBitField2.Flags.PrioritySpeaker
4257
+ ].reduce((a, b) => a | b, 0n);
4258
+ this.runtime.logger.log("Use this URL to add the bot to your server:");
4259
+ this.runtime.logger.log(
4260
+ `https://discord.com/api/oauth2/authorize?client_id=${readyClient.user?.id}&permissions=${requiredPermissions}&scope=bot%20applications.commands`
4261
+ );
4228
4262
  const guilds = await this.client?.guilds.fetch();
4229
4263
  if (!guilds) {
4230
- logger6.warn("Could not fetch guilds, client might not be ready.");
4264
+ this.runtime.logger.warn("Could not fetch guilds, client might not be ready.");
4231
4265
  return;
4232
4266
  }
4233
4267
  for (const [, guild] of guilds) {
@@ -4236,14 +4270,14 @@ var DiscordService = class _DiscordService extends Service {
4236
4270
  const timeoutId = setTimeout(async () => {
4237
4271
  try {
4238
4272
  const fullGuild2 = await guild.fetch();
4239
- logger6.log("DISCORD SERVER CONNECTED", fullGuild2.name);
4273
+ this.runtime.logger.log("DISCORD SERVER CONNECTED", fullGuild2.name);
4240
4274
  this.runtime.emitEvent(["DISCORD_SERVER_CONNECTED" /* WORLD_CONNECTED */], {
4241
4275
  runtime: this.runtime,
4242
4276
  server: fullGuild2,
4243
4277
  source: "discord"
4244
4278
  });
4245
- const worldId = createUniqueUuid6(this.runtime, fullGuild2.id);
4246
- const ownerId = createUniqueUuid6(this.runtime, fullGuild2.ownerId);
4279
+ const worldId = createUniqueUuid5(this.runtime, fullGuild2.id);
4280
+ const ownerId = createUniqueUuid5(this.runtime, fullGuild2.ownerId);
4247
4281
  const standardizedData = {
4248
4282
  name: fullGuild2.name,
4249
4283
  runtime: this.runtime,
@@ -4265,7 +4299,7 @@ var DiscordService = class _DiscordService extends Service {
4265
4299
  };
4266
4300
  this.runtime.emitEvent([EventType2.WORLD_CONNECTED], standardizedData);
4267
4301
  } catch (error) {
4268
- logger6.error("Error during Discord world connection:", error);
4302
+ this.runtime.logger.error("Error during Discord world connection:", error);
4269
4303
  }
4270
4304
  }, 1e3);
4271
4305
  this.timeouts.push(timeoutId);
@@ -4285,7 +4319,7 @@ var DiscordService = class _DiscordService extends Service {
4285
4319
  "discord",
4286
4320
  serviceInstance.handleSendMessage.bind(serviceInstance)
4287
4321
  );
4288
- logger6.info("[Discord] Registered send handler.");
4322
+ runtime.logger.info("[Discord] Registered send handler.");
4289
4323
  }
4290
4324
  }
4291
4325
  /**
@@ -4296,7 +4330,7 @@ var DiscordService = class _DiscordService extends Service {
4296
4330
  * @returns {Promise<Array<{id: string, username: string, displayName: string}>>} A promise that resolves with an array of channel member objects, each containing id, username, and displayName.
4297
4331
  */
4298
4332
  async getTextChannelMembers(channelId, useCache = true) {
4299
- logger6.info(
4333
+ this.runtime.logger.info(
4300
4334
  `Fetching members for text channel ${channelId}, useCache=${useCache}`
4301
4335
  );
4302
4336
  try {
@@ -4304,44 +4338,44 @@ var DiscordService = class _DiscordService extends Service {
4304
4338
  channelId
4305
4339
  );
4306
4340
  if (!channel) {
4307
- logger6.error(`Channel not found: ${channelId}`);
4341
+ this.runtime.logger.error(`Channel not found: ${channelId}`);
4308
4342
  return [];
4309
4343
  }
4310
4344
  if (channel.type !== DiscordChannelType4.GuildText) {
4311
- logger6.error(`Channel ${channelId} is not a text channel`);
4345
+ this.runtime.logger.error(`Channel ${channelId} is not a text channel`);
4312
4346
  return [];
4313
4347
  }
4314
4348
  const guild = channel.guild;
4315
4349
  if (!guild) {
4316
- logger6.error(`Channel ${channelId} is not in a guild`);
4350
+ this.runtime.logger.error(`Channel ${channelId} is not in a guild`);
4317
4351
  return [];
4318
4352
  }
4319
4353
  const useCacheOnly = useCache && guild.memberCount > 1e3;
4320
4354
  let members;
4321
4355
  if (useCacheOnly) {
4322
- logger6.info(
4356
+ this.runtime.logger.info(
4323
4357
  `Using cached members for large guild ${guild.name} (${guild.memberCount} members)`
4324
4358
  );
4325
4359
  members = guild.members.cache;
4326
4360
  } else {
4327
4361
  try {
4328
4362
  if (useCache && guild.members.cache.size > 0) {
4329
- logger6.info(
4363
+ this.runtime.logger.info(
4330
4364
  `Using cached members (${guild.members.cache.size} members)`
4331
4365
  );
4332
4366
  members = guild.members.cache;
4333
4367
  } else {
4334
- logger6.info(`Fetching members for guild ${guild.name}`);
4368
+ this.runtime.logger.info(`Fetching members for guild ${guild.name}`);
4335
4369
  members = await guild.members.fetch();
4336
4370
  logger6.info(`Fetched ${members.size} members`);
4337
4371
  }
4338
4372
  } catch (error) {
4339
- logger6.error(`Error fetching members: ${error}`);
4373
+ this.runtime.logger.error(`Error fetching members: ${error}`);
4340
4374
  members = guild.members.cache;
4341
- logger6.info(`Fallback to cache with ${members.size} members`);
4375
+ this.runtime.logger.info(`Fallback to cache with ${members.size} members`);
4342
4376
  }
4343
4377
  }
4344
- logger6.info(`Filtering members for access to channel ${channel.name}`);
4378
+ this.runtime.logger.info(`Filtering members for access to channel ${channel.name}`);
4345
4379
  const memberArray = Array.from(members.values());
4346
4380
  const channelMembers = memberArray.filter((member) => {
4347
4381
  if (member.user.bot && member.id !== this.client?.user?.id) {
@@ -4353,12 +4387,12 @@ var DiscordService = class _DiscordService extends Service {
4353
4387
  username: member.user.username,
4354
4388
  displayName: member.displayName || member.user.username
4355
4389
  }));
4356
- logger6.info(
4390
+ this.runtime.logger.info(
4357
4391
  `Found ${channelMembers.length} members with access to channel ${channel.name}`
4358
4392
  );
4359
4393
  return channelMembers;
4360
4394
  } catch (error) {
4361
- logger6.error(`Error fetching channel members: ${error}`);
4395
+ this.runtime.logger.error(`Error fetching channel members: ${error}`);
4362
4396
  return [];
4363
4397
  }
4364
4398
  }
@@ -4368,9 +4402,9 @@ var DiscordService = class _DiscordService extends Service {
4368
4402
  */
4369
4403
  async handleReactionAdd(reaction, user) {
4370
4404
  try {
4371
- logger6.log("Reaction added");
4405
+ this.runtime.logger.log("Reaction added");
4372
4406
  if (!reaction || !user) {
4373
- logger6.warn("Invalid reaction or user");
4407
+ this.runtime.logger.warn("Invalid reaction or user");
4374
4408
  return;
4375
4409
  }
4376
4410
  let emoji = reaction.emoji.name;
@@ -4381,22 +4415,22 @@ var DiscordService = class _DiscordService extends Service {
4381
4415
  try {
4382
4416
  await reaction.fetch();
4383
4417
  } catch (error) {
4384
- logger6.error("Failed to fetch partial reaction:", error);
4418
+ this.runtime.logger.error("Failed to fetch partial reaction:", error);
4385
4419
  return;
4386
4420
  }
4387
4421
  }
4388
4422
  const timestamp = Date.now();
4389
- const roomId = createUniqueUuid6(
4423
+ const roomId = createUniqueUuid5(
4390
4424
  this.runtime,
4391
4425
  reaction.message.channel.id
4392
4426
  );
4393
- const entityId = createUniqueUuid6(this.runtime, user.id);
4394
- const reactionUUID = createUniqueUuid6(
4427
+ const entityId = createUniqueUuid5(this.runtime, user.id);
4428
+ const reactionUUID = createUniqueUuid5(
4395
4429
  this.runtime,
4396
4430
  `${reaction.message.id}-${user.id}-${emoji}-${timestamp}`
4397
4431
  );
4398
4432
  if (!entityId || !roomId) {
4399
- logger6.error("Invalid user ID or room ID", {
4433
+ this.runtime.logger.error("Invalid user ID or room ID", {
4400
4434
  entityId,
4401
4435
  roomId
4402
4436
  });
@@ -4411,7 +4445,7 @@ var DiscordService = class _DiscordService extends Service {
4411
4445
  entityId,
4412
4446
  roomId,
4413
4447
  userName,
4414
- worldId: createUniqueUuid6(
4448
+ worldId: createUniqueUuid5(
4415
4449
  this.runtime,
4416
4450
  reaction.message.guild?.id ?? roomId
4417
4451
  ),
@@ -4422,7 +4456,7 @@ var DiscordService = class _DiscordService extends Service {
4422
4456
  serverId: reaction.message.guild?.id,
4423
4457
  type: await this.getChannelType(reaction.message.channel)
4424
4458
  });
4425
- const inReplyTo = createUniqueUuid6(this.runtime, reaction.message.id);
4459
+ const inReplyTo = createUniqueUuid5(this.runtime, reaction.message.id);
4426
4460
  const memory = {
4427
4461
  id: reactionUUID,
4428
4462
  entityId,
@@ -4442,7 +4476,7 @@ var DiscordService = class _DiscordService extends Service {
4442
4476
  };
4443
4477
  const callback = async (content) => {
4444
4478
  if (!reaction.message.channel) {
4445
- logger6.error("No channel found for reaction message");
4479
+ this.runtime.logger.error("No channel found for reaction message");
4446
4480
  return [];
4447
4481
  }
4448
4482
  await reaction.message.channel.send(
@@ -4459,7 +4493,7 @@ var DiscordService = class _DiscordService extends Service {
4459
4493
  }
4460
4494
  );
4461
4495
  } catch (error) {
4462
- logger6.error("Error handling reaction:", error);
4496
+ this.runtime.logger.error("Error handling reaction:", error);
4463
4497
  }
4464
4498
  }
4465
4499
  /**
@@ -4468,7 +4502,7 @@ var DiscordService = class _DiscordService extends Service {
4468
4502
  */
4469
4503
  async handleReactionRemove(reaction, user) {
4470
4504
  try {
4471
- logger6.log("Reaction removed");
4505
+ this.runtime.logger.log("Reaction removed");
4472
4506
  let emoji = reaction.emoji.name;
4473
4507
  if (!emoji && reaction.emoji.id) {
4474
4508
  emoji = `<:${reaction.emoji.name}:${reaction.emoji.id}>`;
@@ -4477,7 +4511,7 @@ var DiscordService = class _DiscordService extends Service {
4477
4511
  try {
4478
4512
  await reaction.fetch();
4479
4513
  } catch (error) {
4480
- logger6.error(
4514
+ this.runtime.logger.error(
4481
4515
  "Something went wrong when fetching the message:",
4482
4516
  error
4483
4517
  );
@@ -4487,13 +4521,13 @@ var DiscordService = class _DiscordService extends Service {
4487
4521
  const messageContent = reaction.message.content || "";
4488
4522
  const truncatedContent = messageContent.length > 50 ? `${messageContent.substring(0, 50)}...` : messageContent;
4489
4523
  const reactionMessage = `*Removed <${emoji}> from: \\"${truncatedContent}\\"*`;
4490
- const roomId = createUniqueUuid6(
4524
+ const roomId = createUniqueUuid5(
4491
4525
  this.runtime,
4492
4526
  reaction.message.channel.id
4493
4527
  );
4494
- const entityId = createUniqueUuid6(this.runtime, user.id);
4528
+ const entityId = createUniqueUuid5(this.runtime, user.id);
4495
4529
  const timestamp = Date.now();
4496
- const reactionUUID = createUniqueUuid6(
4530
+ const reactionUUID = createUniqueUuid5(
4497
4531
  this.runtime,
4498
4532
  `${reaction.message.id}-${user.id}-${emoji}-${timestamp}`
4499
4533
  );
@@ -4503,7 +4537,7 @@ var DiscordService = class _DiscordService extends Service {
4503
4537
  entityId,
4504
4538
  roomId,
4505
4539
  userName,
4506
- worldId: createUniqueUuid6(
4540
+ worldId: createUniqueUuid5(
4507
4541
  this.runtime,
4508
4542
  reaction.message.guild?.id ?? roomId
4509
4543
  ),
@@ -4523,7 +4557,7 @@ var DiscordService = class _DiscordService extends Service {
4523
4557
  // userName,
4524
4558
  text: reactionMessage,
4525
4559
  source: "discord",
4526
- inReplyTo: createUniqueUuid6(this.runtime, reaction.message.id),
4560
+ inReplyTo: createUniqueUuid5(this.runtime, reaction.message.id),
4527
4561
  channelType: await this.getChannelType(
4528
4562
  reaction.message.channel
4529
4563
  )
@@ -4533,7 +4567,7 @@ var DiscordService = class _DiscordService extends Service {
4533
4567
  };
4534
4568
  const callback = async (content) => {
4535
4569
  if (!reaction.message.channel) {
4536
- logger6.error("No channel found for reaction message");
4570
+ this.runtime.logger.error("No channel found for reaction message");
4537
4571
  return [];
4538
4572
  }
4539
4573
  await reaction.message.channel.send(
@@ -4547,7 +4581,7 @@ var DiscordService = class _DiscordService extends Service {
4547
4581
  callback
4548
4582
  });
4549
4583
  } catch (error) {
4550
- logger6.error("Error handling reaction removal:", error);
4584
+ this.runtime.logger.error("Error handling reaction removal:", error);
4551
4585
  }
4552
4586
  }
4553
4587
  /**
@@ -4555,17 +4589,17 @@ var DiscordService = class _DiscordService extends Service {
4555
4589
  * Implements the abstract method from the Service class.
4556
4590
  */
4557
4591
  async stop() {
4558
- logger6.info("Stopping Discord service...");
4592
+ this.runtime.logger.info("Stopping Discord service...");
4559
4593
  this.timeouts.forEach(clearTimeout);
4560
4594
  this.timeouts = [];
4561
4595
  if (this.client) {
4562
4596
  await this.client.destroy();
4563
4597
  this.client = null;
4564
- logger6.info("Discord client destroyed.");
4598
+ this.runtime.logger.info("Discord client destroyed.");
4565
4599
  }
4566
4600
  if (this.voiceManager) {
4567
4601
  }
4568
- logger6.info("Discord service stopped.");
4602
+ this.runtime.logger.info("Discord service stopped.");
4569
4603
  }
4570
4604
  /**
4571
4605
  * Asynchronously retrieves the type of a given channel.
@@ -4582,7 +4616,7 @@ var DiscordService = class _DiscordService extends Service {
4582
4616
  case DiscordChannelType4.GuildVoice:
4583
4617
  return ChannelType9.VOICE_GROUP;
4584
4618
  default:
4585
- logger6.warn(`Unhandled channel type: ${channel.type}`);
4619
+ this.runtime.logger.warn(`Discord unhandled channel type: ${channel.type}`);
4586
4620
  return ChannelType9.GROUP;
4587
4621
  }
4588
4622
  }
@@ -5004,7 +5038,7 @@ var discordPlugin = {
5004
5038
  ],
5005
5039
  providers: [channelStateProvider, voiceStateProvider],
5006
5040
  tests: [new DiscordTestSuite()],
5007
- init: async (config, runtime) => {
5041
+ init: async (_config, runtime) => {
5008
5042
  const token = runtime.getSetting("DISCORD_API_TOKEN");
5009
5043
  if (!token || token.trim() === "") {
5010
5044
  logger8.warn(