Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

djs-fetch

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

djs-fetch

discord.js fetch handler

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
5
66.67%
Maintainers
1
Weekly downloads
 
Created
Source

djs-fetch

djs-fetch: its A powerful utility for efficiently fetching various Discord resources. Simplify your bot development by easily retrieving users, guilds, channels, and more with a consistent and reliable interface.

npm

Download

npm i djs-fetch@latest

How To Add it

const Fetch = require("djs-fetch")
const { Client , GatewayIntentBits } = require("discord.js")
const client = new Client({
      intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
      ],
    })

client.fetch = new Fetch(client)

OR Add it to CustomClient Class

const Fetch = require("djs-fetch")
const { Client , GatewayIntentBits } = require("discord.js")

class CustomClient extends Client {
  constructor() {
    super({
      intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
      ],
    });
this.fetch = new Fetch(this);
 }
}

Examples

1. Fetch User & Users:

// Fetch a user by ID
const userId = "123456789012345678";
const user = await client.fetch.user({ userId }); // or await client.fetch.user(userId)

if (user) {
  console.log(`Fetched user: ${user.username}`);
} else {
  console.log("User not found.");
}
// Fetch all users from a cache by guild ID
const guildId = "987654321098765432";
const users = await client.fetch.users();

if (users) {
  console.log(`Fetched ${users.size} users from guild ${guildId}`);
} else {
  console.log("Users not found.");
}

2. Fetch Channel & Channels:

// Fetch a channel by channel ID
const channelId = "123456789012345678";
const channel = await client.fetch.channel({ channelId });

if (channel) {
  console.log(`Fetched channel: ${channel.name}`);
} else {
  console.log("Channel not found.");
}
// Fetch all channels from a guild by guild ID
const guildId = "987654321098765432";
const channels = await client.fetch.channels({ guildId });

if (channels) {
  console.log(`Fetched ${channels.size} channels from guild ${guildId}`);
} else {
  console.log("Channels not found.");
}

3. All methods

Fetch {
// GUILD 
guild(guildId)
guilds() // No Need

// EMOJI
emoji(emojiId)
emojis(guildId)

// INVITE
invite(inviteCode)
invites(guildId)

// ROLE
role(guildId, roleId)
roles(guildId)

// MEMBER
member(guildId, userId)
members(guildId)

// MESSAGE
message(channelId, messageId)
messages(channelId)

// VOICESTATE
voiceState(guildId, userId)
voiceStates(guildId)

// BAN
ban(guildId, userId)
bans(guildId)

// THREAD
thread(channelId, threadId)
threads(channelId)

// REACTION
reaction(channelId, messageId) {
// REACTION USER
user(userId)
users() // No Need
}

// Usage: client.fetch.<method>

Need Help ?

My Discord Username: devszero

Keywords

n0tzero

FAQs

Package last updated on 28 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts