Fix DiscordBot
All checks were successful
Build App / Build (push) Successful in 1m41s

This commit is contained in:
2025-03-07 14:55:00 +01:00
parent e99479d8fb
commit 9d8a7b3100
5 changed files with 88 additions and 151 deletions

View File

@@ -4,8 +4,12 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.Commands;
using DSharpPlus.Commands.Processors.SlashCommands;
using DSharpPlus.Commands.Processors.TextCommands;
using DSharpPlus.Commands.Processors.TextCommands.Parsing;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity;
using DSharpPlus.CommandsNext;
using DSharpPlus.EventArgs;
using DSharpPlus.Interactivity.Extensions;
//using DSharpPlus.SlashCommands;
@@ -20,7 +24,6 @@ namespace LaDOSE.DiscordBot
{
class Program
{
static DiscordClient discord;
//static InteractivityModule Interactivity { get; set; }
static void Main(string[] args)
@@ -42,107 +45,36 @@ namespace LaDOSE.DiscordBot
var restUrl = builder["REST:Url"].ToString();
var restUser = builder["REST:User"].ToString();
var restPassword = builder["REST:Password"].ToString();
var service = new ServiceCollection()
.AddSingleton(typeof(WebService), new WebService(new Uri(restUrl), restUser, restPassword))
.BuildServiceProvider();
Console.WriteLine($"LaDOSE.Net Discord Bot");
discord = new DiscordClient(new DiscordConfiguration
{
Token = discordToken,
TokenType = TokenType.Bot,
//AutoReconnect = true,
//MinimumLogLevel = LogLevel.Debug,
//MessageCacheSize = 0,
});
discord.UseInteractivity(new InteractivityConfiguration
{
// default pagination behaviour to just ignore the reactions
//PaginationBehaviour = TimeoutBehaviour.Ignore,
// default pagination timeout to 5 minutes
//PaginationTimeout = TimeSpan.FromMinutes(5),
// default timeout for other actions to 2 minutes
Timeout = TimeSpan.FromMinutes(2)
});
DiscordClientBuilder builder2 = DiscordClientBuilder.CreateDefault(discordToken, TextCommandProcessor.RequiredIntents | SlashCommandProcessor.RequiredIntents);
var cts = new CancellationTokenSource();
var _cnext = discord.UseCommandsNext(new CommandsNextConfiguration()
// Setup the commands extension
builder2.UseCommands((IServiceProvider serviceProvider, CommandsExtension extension) =>
{
//CaseSensitive = false,
//EnableDefaultHelp = true,
//EnableDms = false,
//EnableMentionPrefix = true,
StringPrefixes = new List<string>() { "/", "!" },
//IgnoreExtraArguments = true,
Services = service
extension.AddCommands([typeof(Hokuto), typeof(Public)]);
TextCommandProcessor textCommandProcessor = new();
extension.AddProcessor(textCommandProcessor);
}, new CommandsConfiguration()
{
// The default value is true, however it's shown here for clarity
RegisterDefaultCommandProcessors = true,
UseDefaultCommandErrorHandler = false
// DebugGuildId = Environment.GetEnvironmentVariable("DEBUG_GUILD_ID") ?? 0,
});
DiscordClient client = builder2.Build();
//var slashCommands = discord.UseSlashCommands(new SlashCommandsConfiguration() {Services = service});
//slashCommands.RegisterCommands<SlashCommand>(guildId:null);
//_cnext.RegisterCommands<Result>();
_cnext.RegisterCommands<Public>();
//_cnext.RegisterCommands<Shutdown>();
//_cnext.RegisterCommands<Todo>();
_cnext.RegisterCommands<Hokuto>();
_cnext.RegisterCommands<BotEvent>();
foreach (var registeredCommandsKey in discord.GetCommandsNext().RegisteredCommands.Keys)
{
Console.WriteLine(registeredCommandsKey);
}
discord.Ready += (sender, eventArgs) =>
{
Console.WriteLine($"Bot READY.");
return Task.CompletedTask;
};
discord.GuildAvailable += (sender, eventArgs) =>
{
Console.WriteLine($"Joined Guild " + eventArgs.Guild.Name);
return Task.CompletedTask;
};
await discord.ConnectAsync();
// We can specify a status for our bot. Let's set it to "playing" and set the activity to "with fire".
DiscordActivity status = new("Street Fighter", DiscordActivityType.Playing);
await client.ConnectAsync(status,DiscordUserStatus.Online);
await Task.Delay(Timeout.Infinite);
//while (!cts.IsCancellationRequested)
//{
// await Task.Delay(200);
// //if(discord.GetConnectionsAsync().Result.Count)
//}
}
}
//internal class SlashCommand : ApplicationCommandModule
//{
// [SlashCommand("test", "A slash command made to test the DSharpPlusSlashCommands library!")]
// public async Task TestCommand(InteractionContext ctx)
// {
// await ctx.CreateResponseAsync("Lol");
// }
//}
}