Git Product home page Git Product logo

dsharpplus.settingsmanager's Introduction

Rabergsel.DSharpPlus.SettingsManager

Rabergsel.DSharpPlus.SettingsManager is an extension for DSharpPlus that provides an easy infrastructure for managing settings for Discord Servers and Channels.

Installation

This package is under heavy development and not yet available on NuGet. However, you can clone the repository and build the project locally.

Usage

using DSharpPlus;  // Import DSharpPlus library for Discord API
using DSharpPlus.SettingsManager;  // Import DSharpPlus.SettingsManager library for managing settings
using System.IO;  // Import System.IO for file reading

namespace MyFirstBot
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Initialize Discord client
            DiscordClient? discord = new DiscordClient(new DiscordConfiguration()
            {
                // Read bot token from token.txt file
                Token = File.ReadAllText("token.txt"),
                TokenType = TokenType.Bot,  // Set token type as Bot
                Intents = DiscordIntents.All  // Enable all intents for the bot
            });

            // Add default guild setting for reacting to "ping" message
            settings.AddDefaultGuildSetting(new SettingEntity("ReactToPing", false.ToString(), "If set to yes, the bot will react to a \"ping\" message", false));

            // Add SettingsManager extension to Discord client
            discord.AddExtension(settings);

            // Handle message creation event
            discord.MessageCreated += async (s, e) =>
            {
                // Check if guild setting allows reacting to "ping" message
                if (!settings.GetSettingValueAsBoolean(e.Guild.Id, "ReactToPing", false))
                {
                    return;  // Skip if not allowed
                }

                // Check if message content starts with "ping"
                if (e.Message.Content.ToLower().StartsWith("ping"))
                {
                    // Respond with "pong!"
                    await e.Message.RespondAsync("pong!");
                }
            };

            // Connect to Discord
            await discord.ConnectAsync();

            // Keep the application running indefinitely
            await Task.Delay(-1);
        }
    }
}

Note

This package is under heavy development and may undergo frequent changes. It's recommended to keep an eye on updates and consult the documentation for any breaking changes.

User Settings are coming soon.

dsharpplus.settingsmanager's People

Contributors

rabergsel avatar velvettoroyashi avatar

Stargazers

InF avatar  avatar Lunar Starstrum avatar

Watchers

 avatar

Forkers

velvettoroyashi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.