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

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

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:

  1. async function getMessage(channelId, messageId, client) {
  2. const results = await client.shard.broadcastEval(async (c, { channelId, messageId }) => {
  3. const channel = await c.channels.fetch(channelId);
  4. const message = await channel.messages.fetch(messageId);
  5. return message;
  6. }, { context: { channelId, messageId } });
  7. return results.find(result => result !== null);
  8. }
  9. module.exports = getMessage;

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

  1. const message = await getMessage('1114550429917925416', '1118615356701937746', client);
  2. console.log('message', message);
  3. message.edit({ content: 'test' }); // LINE 136
  1. message {
  2. channelId: '1114550429917925416',
  3. guildId: '1060112326361092247',
  4. id: '1118615356701937746',
  5. createdTimestamp: 1686769083906,
  6. type: 0,
  7. system: false,
  8. content: '',
  9. authorId: '829707635787825152',
  10. pinned: false,
  11. tts: false,
  12. nonce: null,
  13. embeds: [
  14. {
  15. type: 'rich',
  16. title: '🎂 **1**',
  17. color: 5197823,
  18. timestamp: '2023-06-14T18:58:03.718000+00:00',
  19. fields: [Array],
  20. footer: [Object]
  21. }
  22. ],
  23. components: [
  24. { type: 1, components: [Array] },
  25. { type: 1, components: [Array] }
  26. ],
  27. attachments: [],
  28. stickers: [],
  29. position: null,
  30. roleSubscriptionData: null,
  31. editedTimestamp: 1686769084345,
  32. mentions: {
  33. everyone: false,
  34. users: [],
  35. roles: [],
  36. crosspostedChannels: [],
  37. repliedUser: null,
  38. members: [],
  39. channels: []
  40. },
  41. webhookId: null,
  42. groupActivityApplicationId: null,
  43. applicationId: null,
  44. activity: null,
  45. flags: 0,
  46. reference: null,
  47. interaction: null,
  48. cleanContent: ''
  49. }
  50. node:events:505
  51. throw er; // Unhandled 'error' event
  52. ^
  53. TypeError: message.edit is not a function
  54. 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:

  1. async function getMessage(channelId, messageId, client) {
  2. const results = await client.shard.broadcastEval(async (c, { channelId, messageId }) => {
  3. const channel = await c.channels.fetch(channelId);
  4. const message = await channel.messages.fetch(messageId);
  5. return message;
  6. }, { context: { channelId, messageId } });
  7. return results.find(result => result !== null);
  8. }
  9. module.exports = getMessage;

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

  1. const message = await getMessage('1114550429917925416', '1118615356701937746', client);
  2. console.log('message', message);
  3. message.edit({content: 'test'}); // LINE 136
  1. message {
  2. channelId: '1114550429917925416',
  3. guildId: '1060112326361092247',
  4. id: '1118615356701937746',
  5. createdTimestamp: 1686769083906,
  6. type: 0,
  7. system: false,
  8. content: '',
  9. authorId: '829707635787825152',
  10. pinned: false,
  11. tts: false,
  12. nonce: null,
  13. embeds: [
  14. {
  15. type: 'rich',
  16. title: '📊 **1**',
  17. color: 5197823,
  18. timestamp: '2023-06-14T18:58:03.718000+00:00',
  19. fields: [Array],
  20. footer: [Object]
  21. }
  22. ],
  23. components: [
  24. { type: 1, components: [Array] },
  25. { type: 1, components: [Array] }
  26. ],
  27. attachments: [],
  28. stickers: [],
  29. position: null,
  30. roleSubscriptionData: null,
  31. editedTimestamp: 1686769084345,
  32. mentions: {
  33. everyone: false,
  34. users: [],
  35. roles: [],
  36. crosspostedChannels: [],
  37. repliedUser: null,
  38. members: [],
  39. channels: []
  40. },
  41. webhookId: null,
  42. groupActivityApplicationId: null,
  43. applicationId: null,
  44. activity: null,
  45. flags: 0,
  46. reference: null,
  47. interaction: null,
  48. cleanContent: ''
  49. }
  50. node:events:505
  51. throw er; // Unhandled 'error' event
  52. ^
  53. TypeError: message.edit is not a function
  54. at Object.execute (/src/events/client/ready.js:136:11)

答案1

得分: 0

  1. 我找到了一个巧妙的解决方案你应该在bEval内部编辑你的消息
  2. ```js
  3. const results = await client.shard.broadcastEval(async (c, { channelId, messageId }) => {
  4. const channel = await c.channels.cache.get(channelId);
  5. const message = await channel.messages.fetch(messageId);
  6. message.edit(); // 在这里
  7. }, { context: { channelId, messageId } });

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

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

  1. <details>
  2. <summary>英文:</summary>
  3. I found a tricky solution, you should edit your message inside the bEval:
  4. ```js
  5. const results = await client.shard.broadcastEval(async (c, { channelId, messageId }) =&gt; {
  6. const channel = await c.channels.cache.get(channelId);
  7. const message = await channel.messages.fetch(messageId);
  8. message.edit(); // HERE
  9. }, { 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:

确定