Discord.Net.BotMvc
1.0.1
dotnet add package Discord.Net.BotMvc --version 1.0.1
NuGet\Install-Package Discord.Net.BotMvc -Version 1.0.1
<PackageReference Include="Discord.Net.BotMvc" Version="1.0.1" />
paket add Discord.Net.BotMvc --version 1.0.1
#r "nuget: Discord.Net.BotMvc, 1.0.1"
// Install Discord.Net.BotMvc as a Cake Addin #addin nuget:?package=Discord.Net.BotMvc&version=1.0.1 // Install Discord.Net.BotMvc as a Cake Tool #tool nuget:?package=Discord.Net.BotMvc&version=1.0.1
Introduction
This library realise a MVC pattern for Discord.Net library.
Discord.Net Modules (ModuleBase
) is a Controller equivalent.
There is also an available DI in all added services.
Configuring
You can configure the bot the way you do it in an ASP project.
class MyBot : BotBase
{
private IConfiguration _config;
public MyBot(IConfiguration config)
: base(config["token"], config["prefix"])
{
_config = config;
}
// Lets configure the bot
protected override Configure(IBotBuilder botBuilder)
{
// Subscribe to some events
botBuilder.Client.OnMessageRecieved += ConsoleLog;
// Or add your own extensions-methods like `.Use*()` in ASP
botBuilder.UsePosts(config => config.AllowCreting = true);
}
protected override ConfigureServices(IServiceCollection services)
{
services.AddSingleton(_config);
services.AddPosts();
services.AddDbContext<SomeDbContext>();
}
// Simple logging
private Task ConsoleLog(LogMessage arg)
{
Console.WriteLine(arg);
return Task.CompletedTask;
}
}
Views
StringMessageResult
Be sure to return the type RuntimeResult
, not StringMessageResult
, ErrorResult
, or your YourOwnResult : RuntimeResult
. Discord.Net allowed to do it only this way. (I hope it will be fixed in future releases of Discord.Net)
[Command("ping")]
public async Task<RuntimeResult> PingAsync()
{
return new StringMessageResult("Pong!");
}
Prints Pong!
message to the channel where this command was called.
EmbedMessageResult & ErrorResult
[Command("help")]
public async Task<RuntimeResult> HelpAsync(string input)
{
var result = _commandService.Search(input);
if (!result.IsSuccess)
// Here
return new ErrorResult(result.Reason);
var command = result.Commands.First();
var eb = new EmbedBuilder()
.WithTitle(command.Aliases.First())
.AddField(command.Remarks, command.Summary);
// And here
return new EmbedMessageResult(eb.Build());
}
Prints coincident embed.
Misc
There are also some stuff, such as
EmoteButton
that allow you to call some a method when a user emote the message.
You need to use the IEmoteFactory
to create new EmoteButton using the method
IEmoteButton Create(IEmote emote, ulong messageId, ButtonTrigger trigger);
, where ButtonTrigger
is delegate Task ButtonTrigger(IUser user)
For example:
class SomeService
{
public static readonly IEmote PlusEmote = new Emoji("\u2795");
public SomeService(IEmoteFactory emoteFactory)
{
emoteFactory.Craete(PlusEmote, Messages.AddNewPostMessageId, OnButtonTriggered);
}
private async Task OnButtonTriggered(IUser user)
{
// do something
}
}
Many more usefulness will be added.
Product | Versions 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 | netcoreapp2.2 is compatible. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.2
- Discord.Net (>= 2.1.1)
- Discord.Net.Commands (>= 2.1.1)
- JetBrains.Annotations (>= 2019.1.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.