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

https://github.com/lachee/discord-chat-preview

Live preview of Discord Channel
https://github.com/lachee/discord-chat-preview

Last synced: 4 months ago
JSON representation

Live preview of Discord Channel

Awesome Lists containing this project

README

          

# Discord Chat Preview

Preview your Discord Chat LIVE. Useful for streams.

![GIF Example](https://raw.githubusercontent.com/Lachee/discord-chat-preview/4020aa08b6ff8387316f759397c65c3144541ebd/example.gif)

# Install
`npm install discord-chat-preview`

# Deps
- Discord.js >= 14
- Express
- Express-WS

# Usage
```js
// Import and configure dotenv.
import dotenv from 'dotenv';
dotenv.config();

// Import discord, express, and express-ws
import { Client, GatewayIntentBits, Partials } from 'discord.js';
import express from 'express';
import expressWebSocket from "express-ws";

// Import the createRouter method from the library
import { createRouter } from 'discord-chat-preview';

// Create the discord client
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent, // This is REQUIRED
GatewayIntentBits.GuildMessages, // This is REQUIRED
GatewayIntentBits.GuildMessageReactions, // This is optional for reactions
],
partials: [Partials.GuildMember, Partials.Message]
});

// Create the express client
const app = express();
const port = process.env.EXPRESS_PORT || 3000;
expressWebSocket(app); // << Make sure you have WS support on your express

// Create the /chat middleware.
// << THIS IS WHAT YOU ADD TO YOUR BOT >>
app.use('/chat', createRouter(client));

// Listen to the react and login with the bot
app.listen(port, () => {
console.log(`Application is listenting too http://localhost:${port}`);
client.login(process.env.BOT_TOKEN);
});
```

# Building
If you fork this package and make changes to how it renders, you need to rebuild it and install the dev dependencies (webpack).
```
npx webpack
```

# Sample Data
to test you can run sample data. Add a `sample.js` that exports a array called `data` with your records. Then build your UI. This will automatically load.