davipatricio / peachy.js

A simple, performance-focused Discord API Wrapper.

Home Page:https://peachyjs.davipatricio.tech

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rkswrites

⚠️ The code here is outdated! New commits will be made on denkylabs/helly.


Installation

Node.js 16.0.0 or newer is required.
npm install peachy.js
yarn add peachy.js
pnpm add peachy.js

Optional packages

  • bufferutil for a much faster WebSocket connection (npm install bufferutil)
  • utf-8-validate in combination with bufferutil for much faster WebSocket processing (npm install utf-8-validate)

Simple example

const Peachy = require('peachy.js');
const client = new Peachy.Client();

client.on('messageCreate', async (msg) => {
   if (msg.content === '!ping') msg.channel.send(`Pong! ${client.ping}ms.`);
});

client.login('Bot token');

Advanced example

const Peachy = require('peachy.js');
const client = new Peachy.Client({
    // Disabling some events can eventually improve performance on bots on many servers in combination with intents
    // Event list: https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
    disabledEvents: ['TYPING_START'],
    
    shardId: 0, // Should start at 0. Useful for large bots in multiple machines
    shardCount: 1, // How many shards spawn
    autoReconnect: true,

    intents: ['GUILDS', 'GUILD_MESSAGES'],
    
    // You can limit the caching of certain items to decrease memory consumption.
    // Leaving some items at 0 or at a very low value may cause some properties not to be available without the 'fetch' method.
    caches: {
        guilds: Infinity, // May break the entire bot, not recommended to disable.
        channels: Infinity, // If disabled, you won't be able to see properties and permissions for a channel through the cache.
        roles: 2500, // If disabled, you won't be able to see member properties, permissions through the cache.
        users: 100, // If disabled, you won't be able to get some information from users through the cache.
        membersPerGuild: 1000, // If disabled, you won't be able to get some member information through the cache.
        emojis: 0 // If disabled, you won't be able to search for emojis through the cache.
    }
});

client.login('Bot token');

client.on('messageCreate', async (msg) => {
   if (msg.content === '!ping') msg.channel.send(`Pong! ${client.ping}ms.`);
   if (msg.content === '!say') {
      await msg.delete();
      msg.channel.send(msg.content.slice(4));
   }
   if (msg.content === '!servers') msg.channel.send(`I'm in ${client.guilds.cache.size} guilds!`);
});


client.once('ready', () => console.log('Connected to Discord!'));

About

A simple, performance-focused Discord API Wrapper.

https://peachyjs.davipatricio.tech

License:Apache License 2.0


Languages

Language:JavaScript 100.0%