Agregar archivos de proyecto.
This commit is contained in:
parent
24fcabeece
commit
2f3fbad29e
7 changed files with 353 additions and 0 deletions
78
Bot_Discord_CSharp/Bot.cs
Normal file
78
Bot_Discord_CSharp/Bot.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.EventArgs;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Bot_Discord_CSharp.Dto;
|
||||
using Bot_Discord_CSharp.Commands;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.Interactivity.Extensions;
|
||||
|
||||
namespace Bot_Discord_CSharp
|
||||
{
|
||||
public class Bot
|
||||
{
|
||||
public DiscordClient Client { get; private set; }
|
||||
public InteractivityExtension Interactivity { get; private set; }
|
||||
public CommandsNextExtension Commands { get; private set; }
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
var json = string.Empty;
|
||||
|
||||
using (var fs = File.OpenRead(@"E:\Proyectos Visual Studio\Bot_Discord_CSharp\Bot_Discord_CSharp\config.json"))
|
||||
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||
json = await sr.ReadToEndAsync().ConfigureAwait(false);
|
||||
|
||||
var configJson = JsonConvert.DeserializeObject<ConfigDto>(json);
|
||||
|
||||
var config = new DiscordConfiguration
|
||||
{
|
||||
Token = configJson.Token,
|
||||
TokenType = TokenType.Bot,
|
||||
AutoReconnect = true,
|
||||
MinimumLogLevel = LogLevel.Debug
|
||||
};
|
||||
|
||||
Client = new DiscordClient(config);
|
||||
|
||||
Client.Ready += OnClientReady;
|
||||
|
||||
Client.UseInteractivity(new InteractivityConfiguration
|
||||
{
|
||||
Timeout = TimeSpan.FromMinutes(1)
|
||||
});
|
||||
|
||||
var commandsConfig = new CommandsNextConfiguration
|
||||
{
|
||||
StringPrefixes = new string[] { configJson.Prefix },
|
||||
EnableDms = false,
|
||||
EnableMentionPrefix = true,
|
||||
DmHelp = false
|
||||
};
|
||||
|
||||
Commands = Client.UseCommandsNext(commandsConfig);
|
||||
|
||||
RegisterCommands();
|
||||
|
||||
await Client.ConnectAsync();
|
||||
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
|
||||
private Task OnClientReady(DiscordClient client, ReadyEventArgs e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private void RegisterCommands()
|
||||
{
|
||||
Commands.RegisterCommands<TestCommand>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue