1.5.4 • Published 11 months ago

dcdash v1.5.4

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

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.

1.5.4

11 months ago

1.5.3

11 months ago

1.5.2

11 months ago

1.5.1

11 months ago

1.0.4

11 months ago

1.0.2

11 months ago

1.0.0

11 months ago