npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dcdash

v1.5.4

Published

Adds a dashboard to your existing discord bot.

Downloads

11

Readme

Discord Bot Settings Dashboard Package

This npm package provides a web-based dashboard for managing settings of a Discord bot. It enables bot developers to integrate a settings dashboard into their Discord bots, allowing settings like prefixes and welcome messages to be updated dynamically through a web interface. The package also uses SweetAlert2 for stylish alerts and notifications.

Features

  • Dashboard Integration: Easily integrate a settings dashboard into your Discord bot.
  • Dynamic Settings Management: Add and update settings for each guild dynamically.
  • SweetAlert2 Alerts: Stylish notifications for user feedback after updates.

Installation

  1. Install the package:

    npm install dcdash@latest
  2. Set up environment variables: Ensure you have the following environment variables set in your .env file:

    TOKEN=your-discord-bot-token
    MONGO_URL=your-mongodb-connection-url
    CLIENT_ID="bot id"
    CLIENT_SECRET="bot secret"
    REDIRECT_URI=http://<url>/auth/discord/callback
    SECRET="any strong secret for session"
  3. Initialize the Dashboard: In your index.js or main bot file, initialize the dashboard and connect to MongoDB.

    require('dotenv').config();
    const { Client, GatewayIntentBits } = require('discord.js');
    const { startDashboard, setSlashCmds } = require('your-package-name');
    const { connectMongoDB, setSettings, getSettings } = require('your-package-name');
    const { loadSlashCommands, handleSlashCommands } = require('./commandHandler');
    
    // Connect to MongoDB
    connectMongoDB(process.env.MONGO_URL);
    
    const client = new Client({ intents: Object.keys(GatewayIntentBits) });
    
    client.once('ready', async () => {
        console.log(`Logged in as ${client.user.tag}`);
    
        // Initialize the dashboard
        startDashboard(client, { port: 3000 });
    
        // Load slash commands
        loadSlashCommands(client);
    
        // Prepare command data for the dashboard
        const commands = client.slashCommands.map(cmd => cmd.data.toJSON());
        const commandDisplayData = commands.map(cmd => ({
            name: cmd.name,
            description: cmd.description || 'No description available',
            usage: client.slashCommands.find(c => c.data.name === cmd.name)?.usage || 'No usage information available'
        }));
        setSlashCmds(commandDisplayData);
    
        // Register slash commands with Discord API
        await client.application.commands.set(commands).catch(console.error);
    
        // Initialize default settings (if any)
        client.guilds.cache.forEach(async guild => {
            const guildSettings = await getSettings(guild.id);
            const Settings = [
                { name: 'prefix', type: 'text', value: '!' },
                { name: 'msg', type: 'text', value: 'Hello World!' }
            ];
            const existingSettings = guildSettings.map(setting => setting.name);
            const settingsToAdd = Settings.filter(setting => !existingSettings.includes(setting.name));
    
            if (settingsToAdd.length > 0) {
                await setSettings(guild.id, settingsToAdd);
            }
    
            const prefixSetting = guildSettings.find(setting => setting.name === 'prefix');
            client.prefixes = client.prefixes || {};
            client.prefixes[guild.id] = prefixSetting ? prefixSetting.value : '!';
        });
    });
    
    client.on('messageCreate', async message => {
        if (!message.guild) return;
        const guildSettings = await getSettings(message.guild.id);
        const prefixSetting = guildSettings.find(setting => setting.name === 'prefix');
        const msgSetting = guildSettings.find(setting => setting.name === 'msg');
        const prefix = prefixSetting ? prefixSetting.value : '!';
        const msg = msgSetting ? msgSetting.value : 'Hello World!';
    
        if (message.content.startsWith(prefix)) {
            const args = message.content.slice(prefix.length).trim().split(/ +/);
            const command = args.shift().toLowerCase();
    
            if (command === "hello") {
                message.reply(msg);
            }
        }
    });
    
    client.on('interactionCreate', interaction => {
        handleSlashCommands(interaction);
    });
    
    client.login(process.env.TOKEN).catch(console.error);

Usage

  1. Create a dashboard for your bot: Use startDashboard(client, { port: 3000 }) to initialize the dashboard and make it accessible at http://localhost:3000.

  2. Define settings: Use the setSettings and getSettings functions to manage settings for each guild. The settings will be accessible and editable through the dashboard.

  3. Handle commands: Register and handle slash commands using loadSlashCommands and handleSlashCommands functions on the dashboard.

SweetAlert2 Integration

SweetAlert2 is used for notifications. To integrate and use SweetAlert2 alerts, you can include the library in your dashboard page and use it as needed for displaying messages.

For more details, visit the SweetAlert2 documentation.

Contributing

Feel free to contribute to this project by submitting issues or pull requests. Your feedback and contributions are welcome!

License

This project is licensed under the MIT License. See the LICENSE file for details.