使用分片编辑具有频道ID和消息ID的消息

huangapple go评论59阅读模式
英文:

Edit message with channel id and message id using shards

问题

I'm trying to edit a specific message in a specific channel.
I have a getMessage function that returns me the channel using broadcastEval because I use shards:

async function getMessage(channelId, messageId, client) {
  const results = await client.shard.broadcastEval(async (c, { channelId, messageId }) => {
    const channel = await c.channels.fetch(channelId);
    const message = await channel.messages.fetch(messageId);
    return message;
  }, { context: { channelId, messageId } });
  return results.find(result => result !== null);
}

module.exports = getMessage;

And when I try to edit my message, I cannot do it:

const message = await getMessage('1114550429917925416', '1118615356701937746', client);
console.log('message', message);
message.edit({ content: 'test' }); // LINE 136
message {
  channelId: '1114550429917925416',
  guildId: '1060112326361092247',
  id: '1118615356701937746',
  createdTimestamp: 1686769083906,
  type: 0,
  system: false,
  content: '',
  authorId: '829707635787825152',
  pinned: false,
  tts: false,
  nonce: null,
  embeds: [
    {
      type: 'rich',
      title: '🎂 **1**',
      color: 5197823,
      timestamp: '2023-06-14T18:58:03.718000+00:00',
      fields: [Array],
      footer: [Object]
    }
  ],
  components: [
    { type: 1, components: [Array] },
    { type: 1, components: [Array] }
  ],
  attachments: [],
  stickers: [],
  position: null,
  roleSubscriptionData: null,
  editedTimestamp: 1686769084345,
  mentions: {
    everyone: false,
    users: [],
    roles: [],
    crosspostedChannels: [],
    repliedUser: null,
    members: [],
    channels: []
  },
  webhookId: null,
  groupActivityApplicationId: null,
  applicationId: null,
  activity: null,
  flags: 0,
  reference: null,
  interaction: null,
  cleanContent: ''
}
node:events:505
      throw er; // Unhandled 'error' event
      ^

TypeError: message.edit is not a function
    at Object.execute (/src/events/client/ready.js:136:11)
英文:

im trying to edit a specific message in a specific channel.
I have getMessage function than return me the channel using broadcastEval because i use shards:

async function getMessage(channelId, messageId, client) {
  const results = await client.shard.broadcastEval(async (c, { channelId, messageId }) => {
    const channel = await c.channels.fetch(channelId);
    const message = await channel.messages.fetch(messageId);
    return message;
  }, { context: { channelId, messageId } });
  return results.find(result => result !== null);
}

module.exports = getMessage;

And when I try to edit my message I cannot do it:

const message = await getMessage('1114550429917925416', '1118615356701937746', client);
console.log('message', message);
message.edit({content: 'test'}); // LINE 136
message {
  channelId: '1114550429917925416',
  guildId: '1060112326361092247',
  id: '1118615356701937746',
  createdTimestamp: 1686769083906,
  type: 0,
  system: false,
  content: '',
  authorId: '829707635787825152',
  pinned: false,
  tts: false,
  nonce: null,
  embeds: [
    {
      type: 'rich',
      title: '📊 **1**',
      color: 5197823,
      timestamp: '2023-06-14T18:58:03.718000+00:00',
      fields: [Array],
      footer: [Object]
    }
  ],
  components: [
    { type: 1, components: [Array] },
    { type: 1, components: [Array] }
  ],
  attachments: [],
  stickers: [],
  position: null,
  roleSubscriptionData: null,
  editedTimestamp: 1686769084345,
  mentions: {
    everyone: false,
    users: [],
    roles: [],
    crosspostedChannels: [],
    repliedUser: null,
    members: [],
    channels: []
  },
  webhookId: null,
  groupActivityApplicationId: null,
  applicationId: null,
  activity: null,
  flags: 0,
  reference: null,
  interaction: null,
  cleanContent: ''
}
node:events:505
      throw er; // Unhandled 'error' event
      ^

TypeError: message.edit is not a function
    at Object.execute (/src/events/client/ready.js:136:11)

答案1

得分: 0

我找到了一个巧妙的解决方案你应该在bEval内部编辑你的消息

```js
const results = await client.shard.broadcastEval(async (c, { channelId, messageId }) => {
  const channel = await c.channels.cache.get(channelId);
  const message = await channel.messages.fetch(messageId);
  message.edit();    // 在这里
}, { context: { channelId, messageId } });

如果你想在其中调用另一个函数,请在之前声明它:
client.myFunction = myFunction;

然后在bEval内调用它:
c.myFunction();


<details>
<summary>英文:</summary>

I found a tricky solution, you should edit your message inside the bEval:

```js
const results = await client.shard.broadcastEval(async (c, { channelId, messageId }) =&gt; {
  const channel = await c.channels.cache.get(channelId);
  const message = await channel.messages.fetch(messageId);
  message.edit();    // HERE
}, { context: { channelId, messageId } });

And if you want to call another function inside it declare it before:
client.myFunction = myFunction;

And after call it inside the bEval:
c.myFunction();

huangapple
  • 本文由 发表于 2023年6月15日 23:40:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定