@elizaos/plugin-discord 1.3.2 → 1.3.3

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
@@ -4050,8 +4050,7 @@ import {
4050
4050
  EventType,
4051
4051
  Role,
4052
4052
  Service,
4053
- createUniqueUuid as createUniqueUuid5,
4054
- logger as logger13
4053
+ createUniqueUuid as createUniqueUuid5
4055
4054
  } from "@elizaos/core";
4056
4055
  import {
4057
4056
  ChannelType as DiscordChannelType5,
@@ -4813,7 +4812,7 @@ var MessageManager = class {
4813
4812
  },
4814
4813
  createdAt: message.createdTimestamp
4815
4814
  };
4816
- const callback = async (content, files) => {
4815
+ const callback = async (content) => {
4817
4816
  try {
4818
4817
  if (content.target && typeof content.target === "string" && content.target.toLowerCase() !== "discord") {
4819
4818
  return [];
@@ -4850,7 +4849,7 @@ var MessageManager = class {
4850
4849
  channel,
4851
4850
  content.text ?? "",
4852
4851
  message.id,
4853
- files || []
4852
+ []
4854
4853
  );
4855
4854
  }
4856
4855
  const memories = [];
@@ -4889,7 +4888,19 @@ var MessageManager = class {
4889
4888
  return [];
4890
4889
  }
4891
4890
  };
4892
- await this.runtime.messageService.handleMessage(this.runtime, newMessage, callback);
4891
+ if (this.runtime.hasElizaOS()) {
4892
+ logger11.debug("[Discord] Using unified messaging API");
4893
+ await this.runtime.elizaOS.sendMessage(
4894
+ this.runtime.agentId,
4895
+ newMessage,
4896
+ {
4897
+ onResponse: callback
4898
+ }
4899
+ );
4900
+ } else {
4901
+ logger11.debug("[Discord] Using direct message service");
4902
+ await this.runtime.messageService.handleMessage(this.runtime, newMessage, callback);
4903
+ }
4893
4904
  setTimeout(() => {
4894
4905
  if (typingData.started && typingData.interval && !typingData.cleared) {
4895
4906
  clearInterval(typingData.interval);
@@ -5880,7 +5891,6 @@ var DiscordService = class _DiscordService extends Service {
5880
5891
  discordSettings;
5881
5892
  userSelections = /* @__PURE__ */ new Map();
5882
5893
  timeouts = [];
5883
- clientReadyPromise;
5884
5894
  /**
5885
5895
  * List of allowed channel IDs (parsed from CHANNEL_IDS env var).
5886
5896
  * If undefined, all channels are allowed.
@@ -5905,7 +5915,7 @@ var DiscordService = class _DiscordService extends Service {
5905
5915
  const channelIdsRaw = runtime.getSetting("CHANNEL_IDS");
5906
5916
  if (channelIdsRaw?.trim && channelIdsRaw.trim()) {
5907
5917
  this.allowedChannelIds = channelIdsRaw.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
5908
- this.runtime.logger.debug("Locking down discord to", this.allowedChannelIds);
5918
+ this.runtime.logger.debug("Locking down discord to", this.allowedChannelIds.join(", "));
5909
5919
  }
5910
5920
  const token = runtime.getSetting("DISCORD_API_TOKEN");
5911
5921
  if (!token || token?.trim && token.trim() === "") {
@@ -5932,17 +5942,18 @@ var DiscordService = class _DiscordService extends Service {
5932
5942
  this.runtime = runtime;
5933
5943
  this.voiceManager = new VoiceManager(this, runtime);
5934
5944
  this.messageManager = new MessageManager(this);
5935
- this.clientReadyPromise = new Promise((resolver) => {
5936
- this.client.once(Events.ClientReady, (readyClient) => {
5937
- resolver();
5938
- this.onReady(readyClient);
5939
- });
5940
- this.client.login(token).catch((error) => {
5941
- this.runtime.logger.error(
5942
- `Failed to login to Discord: ${error instanceof Error ? error.message : String(error)}`
5943
- );
5944
- this.client = null;
5945
- });
5945
+ this.client.once(Events.ClientReady, (readyClient) => {
5946
+ this.onReady(readyClient);
5947
+ });
5948
+ this.client.login(token).catch((error) => {
5949
+ this.runtime.logger.error(
5950
+ `Failed to login to Discord: ${error instanceof Error ? error.message : String(error)}`
5951
+ );
5952
+ if (this.client) {
5953
+ this.client.destroy().catch(() => {
5954
+ });
5955
+ }
5956
+ this.client = null;
5946
5957
  });
5947
5958
  this.setupEventListeners();
5948
5959
  this.registerSendHandler();
@@ -6069,8 +6080,6 @@ var DiscordService = class _DiscordService extends Service {
6069
6080
  }
6070
6081
  const listenCidsRaw = this.runtime.getSetting("DISCORD_LISTEN_CHANNEL_IDS");
6071
6082
  const listenCids = Array.isArray(listenCidsRaw) ? listenCidsRaw : listenCidsRaw && typeof listenCidsRaw === "string" && listenCidsRaw.trim() ? listenCidsRaw.trim().split(",").map((s) => s.trim()).filter((s) => s.length > 0) : [];
6072
- const talkCids = this.allowedChannelIds ?? [];
6073
- const allowedCids = [...listenCids, ...talkCids];
6074
6083
  this.client.on("messageCreate", async (message) => {
6075
6084
  if (message.author.id === this.client?.user?.id || message.author.bot && this.discordSettings.shouldIgnoreBotMessages) {
6076
6085
  this.runtime.logger.info(
@@ -6080,26 +6089,25 @@ var DiscordService = class _DiscordService extends Service {
6080
6089
  }
6081
6090
  if (listenCids.includes(message.channel.id)) {
6082
6091
  const entityId = createUniqueUuid5(this.runtime, message.author.id);
6083
- const userName = message.author.bot ? `${message.author.username}#${message.author.discriminator}` : message.author.username;
6084
- const name = message.author.displayName;
6085
- const channelId = message.channel.id;
6086
- const roomId = createUniqueUuid5(this.runtime, channelId);
6092
+ const roomId = createUniqueUuid5(this.runtime, message.channel.id);
6087
6093
  let type;
6088
- let serverId;
6094
+ let _serverId;
6089
6095
  if (message.guild) {
6090
6096
  const guild = await message.guild.fetch();
6091
6097
  type = await this.getChannelType(message.channel);
6092
6098
  if (type === null) {
6093
- this.runtime.logger.warn("null channel type, discord message", message);
6099
+ this.runtime.logger.warn("null channel type, discord message", message.id);
6094
6100
  }
6095
- serverId = guild.id;
6101
+ _serverId = guild.id;
6096
6102
  } else {
6097
6103
  type = ChannelType7.DM;
6098
- serverId = message.channel.id;
6104
+ _serverId = message.channel.id;
6099
6105
  }
6100
6106
  const { processedContent, attachments } = await this.messageManager.processMessage(message);
6101
6107
  const messageId = createUniqueUuid5(this.runtime, message.id);
6102
6108
  const sourceId = entityId;
6109
+ const userName = message.author.bot ? `${message.author.username}#${message.author.discriminator}` : message.author.username;
6110
+ const name = message.member?.displayName ?? message.author.displayName ?? message.author.globalName ?? userName;
6103
6111
  const newMessage = {
6104
6112
  id: messageId,
6105
6113
  entityId,
@@ -6739,7 +6747,7 @@ var DiscordService = class _DiscordService extends Service {
6739
6747
  } else {
6740
6748
  this.runtime.logger.info(`Fetching members for guild ${guild.name}`);
6741
6749
  members = await guild.members.fetch();
6742
- logger13.info(`Fetched ${members.size} members`);
6750
+ this.runtime.logger.info(`Fetched ${members.size} members`);
6743
6751
  }
6744
6752
  } catch (error) {
6745
6753
  this.runtime.logger.error(`Error fetching members: ${error}`);