Advertisement
crutch12

add/remove reactions to all discord messages in channel

Dec 17th, 2021
1,193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var channelId = '920994048523788319';
  2.  
  3. // берём из любого запроса
  4. var authorization = 'NDY1MTk1MTc5Mjk3NjAzNTg0.YZzAEw.O1Hr7eACh2wO3b43tZJ4sYESc3c';
  5.  
  6. // @NOTE: запрашиваем сообщения треда
  7. var messages = await fetch(`https://discord.com/api/v9/channels/${channelId}/messages?limit=100`, {
  8.   headers: {
  9.     authorization,
  10.   },
  11. }).then(r => r.json());
  12.  
  13. // '👀'
  14. var reactions = ['✅', '❎']
  15.  
  16. async function addReactions(messages, reactions) {
  17.   for (var message of messages) {
  18.     for (var reaction of reactions) {
  19.       await fetch(`https://discord.com/api/v9/channels/${channelId}/messages/${message.id}/reactions/${encodeURIComponent(`${reaction}/@me`)}`, {
  20.         headers: {
  21.           authorization,
  22.         },
  23.         method: 'PUT',
  24.       }).then(r => r.text())
  25.       await new Promise(resolve => setTimeout(resolve, 300))
  26.     }
  27.   }
  28. }
  29.  
  30. async function removeReactions(messages, reactions) {
  31.   for (var message of messages) {
  32.     for (var reaction of reactions) {
  33.       await fetch(`https://discord.com/api/v9/channels/${channelId}/messages/${message.id}/reactions/${encodeURIComponent(`${reaction}/@me`)}`, {
  34.         headers: {
  35.           authorization,
  36.         },
  37.         method: 'DELETE',
  38.       }).then(r => r.text())
  39.       await new Promise(resolve => setTimeout(resolve, 300))
  40.     }
  41.   }
  42. }
  43.  
  44. // @NOTE: добавить выбранные реакции ко всем сообщениям
  45. await addReactions(messages, reactions);
  46.  
  47. // @NOTE: удалить выбранные реакции для всех сообщений
  48. await removeReactions(messages, reactions);
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement