Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ayfri/discord-fetch-messages

A npm package to fetch all of the messages of a channel, channel list or a guild, using discord.js.
https://github.com/ayfri/discord-fetch-messages

discord discord-bot discord-js discord-messages fetch fetching

Last synced: 10 days ago
JSON representation

A npm package to fetch all of the messages of a channel, channel list or a guild, using discord.js.

Awesome Lists containing this project

README

        

![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/Ayfri/discord-fetch-messages)
![npm](https://img.shields.io/npm/dt/discord-fetch-messages)
![npm](https://img.shields.io/npm/v/discord-fetch-messages?label=latest%20version)
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/Ayfri/discord-fetch-messages.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Ayfri/discord-fetch-messages/context:javascript)

# discord-fetch

A npm package to fetch all the messages from a guild, a channel or a thread.

## How to use it

⚠️ READ BEFORE USING ⚠️

These operations took a long time to process. Be patient and avoid doing this often because it's doing a lot of requests to Discord and you can be banned for sending too many requests to Discord.

⚠️ READ BEFORE USING ⚠️

```js
const fetcher = new Fetcher(client);

fetcher.on('fetchChannel', async channel => {
await message.channel.send(`Fetching <#${channel.id}>.`);
});

const guildMessages = await fetcher.fetchGuild(guildID);
const channelMessages = await fetcher.fetchChannel(channel);
const threadMessages = await fetcher.fetchThread(thread);

const channelsMessages = await fetcher.fetchChannels(
guild.channels.filter(channel => channel.isText() && !channel.isThread() && channel.name.startsWith('g'))
);
const guildMessagesAndThreads = await fetcher.fetchGuild(guildID, true);

const threadsMessages = await fetcher.fetchThreads(threadsIDs, parentChannelOfThreads);
```

## Event list :

| Event Name | Description | Arguments |
| -------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ |
| `fetchChannel` | Emitter when fetching a Channel. | `channel`: The channel fetched. |
| `fetchGuild` | Emitted when fetching a Guild. | `guild`: The guild fetched. |
| `fetch` | Emitted after fetched a bulk a of messages, can fetch 0 to 100 messages. | `length`: The number of messages fetched.
`messages`: The messages fetched, as a Collection. |
| `fetchThread` | Emitted when fetching a Thread. | `thread`: The thread fetched.
`channel`: The parent channel of the thread. |

You can also use a `fetching` boolean property that is set to true when fetching a bulk of message, then to false.

> Note :
>
> Node.js > 16 is required.