DiscordFeature 2.1.1

dotnet add package DiscordFeature --version 2.1.1
NuGet\Install-Package DiscordFeature -Version 2.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DiscordFeature" Version="2.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DiscordFeature --version 2.1.1
#r "nuget: DiscordFeature, 2.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DiscordFeature as a Cake Addin
#addin nuget:?package=DiscordFeature&version=2.1.1

// Install DiscordFeature as a Cake Tool
#tool nuget:?package=DiscordFeature&version=2.1.1

DiscordFeature

A tiny library for easily creating features for discord bots using Discord.Net.

Usage

using Discord;
using Discord.WebSocket;
using static Discord.Feature;

// Login to discord
DiscordSocketConfig config = new() { AlwaysDownloadUsers = true, MessageCacheSize = 1000 };
// Reads from a file called 'token.tok' where the discord bot token is stored
await LoginAsync(TokenType.Bot, File.ReadAllText("token.tok"), config);

// Prevents the application from closing until specific word is entered
await LogoutKeyword("exit");

Creating a new Feature

To create a new feature simply create a new class and have it inherit from 'Discord.Feature' or just 'Feature' if 'using Discord' is used.

using Discord;
using Discord.WebSocket;

internal class NewDiscordFeature : Feature
{
    
}

Finally you need to override the 'Init' method so that you can setup the Feature.

using Discord;
using Discord.WebSocket;

internal class NewDiscordFeature : Feature
{
    public override void Init(in DiscordSocketClient client)
    {
        client.MessageReceived += Client_MessageReceived;

        // Add more as needed
    }

    private Task Client_MessageReceived(SocketMessage arg)
    {
        Console.WriteLine(arg.Content);
        return Task.CompletedTask;
    }
}

And thats it, you don't need to create any instances for these features, they will be created automatically at runtime.

Project structure

To keep things nice and neat I recommend creating a new folder called 'Features' and in that create a folder for each new feature where you would then create your feature class and other files specific to that feature in it.

It should look like so.

Project Structure

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.1 289 12/22/2021
2.1.0 227 12/22/2021
2.0.1 237 12/21/2021
2.0.0 228 12/20/2021
1.0.0 237 12/20/2021