diff --git a/Example-Bots.sln b/Example-Bots.sln index 101209b..d9bd3fe 100644 --- a/Example-Bots.sln +++ b/Example-Bots.sln @@ -17,7 +17,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Examples.Compone EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Examples.Components.Modals", "src\DSharpPlus.Examples.Components.Modals\DSharpPlus.Examples.Components.Modals.csproj", "{C5197139-4026-4EE9-A301-136FC3E10DA3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Examples.CommandsNext.Basics", "src\DSharpPlus.Examples.CommandsNext.Basics\DSharpPlus.Examples.CommandsNext.Basics.csproj", "{7135C15F-A8FD-4CEB-BA07-ED45FFBFFFF5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Examples.Commands.Basics", "src\DSharpPlus.Examples.Commands.Basics\DSharpPlus.Examples.Commands.Basics.csproj", "{7135C15F-A8FD-4CEB-BA07-ED45FFBFFFF5}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Examples.CommandsNext.CommandArguments", "src\DSharpPlus.Examples.CommandsNext.CommandArguments\DSharpPlus.Examples.CommandsNext.CommandArguments.csproj", "{1159DF74-2834-4A7B-97C2-384C8578F6A6}" EndProject diff --git a/src/DSharpPlus.Examples.Basics.HelloWorld/DSharpPlus.Examples.Basics.HelloWorld.csproj b/src/DSharpPlus.Examples.Basics.HelloWorld/DSharpPlus.Examples.Basics.HelloWorld.csproj index 1641155..22dabcd 100644 --- a/src/DSharpPlus.Examples.Basics.HelloWorld/DSharpPlus.Examples.Basics.HelloWorld.csproj +++ b/src/DSharpPlus.Examples.Basics.HelloWorld/DSharpPlus.Examples.Basics.HelloWorld.csproj @@ -1,10 +1,10 @@  Exe - net7.0 + net8.0 enable - + \ No newline at end of file diff --git a/src/DSharpPlus.Examples.Basics.Logging/DSharpPlus.Examples.Basics.Logging.csproj b/src/DSharpPlus.Examples.Basics.Logging/DSharpPlus.Examples.Basics.Logging.csproj index 66f7d3f..eee5a79 100644 --- a/src/DSharpPlus.Examples.Basics.Logging/DSharpPlus.Examples.Basics.Logging.csproj +++ b/src/DSharpPlus.Examples.Basics.Logging/DSharpPlus.Examples.Basics.Logging.csproj @@ -1,11 +1,11 @@  Exe - net7.0 + net8.0 enable - + diff --git a/src/DSharpPlus.Examples.Basics.MessageBuilder/DSharpPlus.Examples.Basics.MessageBuilder.csproj b/src/DSharpPlus.Examples.Basics.MessageBuilder/DSharpPlus.Examples.Basics.MessageBuilder.csproj index 1641155..22dabcd 100644 --- a/src/DSharpPlus.Examples.Basics.MessageBuilder/DSharpPlus.Examples.Basics.MessageBuilder.csproj +++ b/src/DSharpPlus.Examples.Basics.MessageBuilder/DSharpPlus.Examples.Basics.MessageBuilder.csproj @@ -1,10 +1,10 @@  Exe - net7.0 + net8.0 enable - + \ No newline at end of file diff --git a/src/DSharpPlus.Examples.Commands.Basics/Commands/PingCommand.cs b/src/DSharpPlus.Examples.Commands.Basics/Commands/PingCommand.cs new file mode 100644 index 0000000..e789ae2 --- /dev/null +++ b/src/DSharpPlus.Examples.Commands.Basics/Commands/PingCommand.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; +using DSharpPlus.Commands.Processors.TextCommands.Attributes; +using DSharpPlus.Commands.Trees; +using DSharpPlus.Commands.Trees.Attributes; + +namespace DSharpPlus.Examples.Commands.Basics +{ + public sealed class PingCommand + { + [Command("ping"), TextAlias("pong")] + public static ValueTask ExecuteAsync(CommandContext context) => context.RespondAsync($"Pong! Latency is {context.Client.Ping}ms."); + } +} diff --git a/src/DSharpPlus.Examples.Commands.Basics/DSharpPlus.Examples.Commands.Basics.csproj b/src/DSharpPlus.Examples.Commands.Basics/DSharpPlus.Examples.Commands.Basics.csproj new file mode 100644 index 0000000..809351d --- /dev/null +++ b/src/DSharpPlus.Examples.Commands.Basics/DSharpPlus.Examples.Commands.Basics.csproj @@ -0,0 +1,18 @@ + + + Exe + net8.0 + enable + DSharpPlus.Examples.Commands.Basics + + + + + + + + + + + + \ No newline at end of file diff --git a/src/DSharpPlus.Examples.Commands.Basics/Program.cs b/src/DSharpPlus.Examples.Commands.Basics/Program.cs new file mode 100644 index 0000000..b28be89 --- /dev/null +++ b/src/DSharpPlus.Examples.Commands.Basics/Program.cs @@ -0,0 +1,57 @@ +using System; +using System.Reflection; +using System.Threading.Tasks; +using DSharpPlus.Commands; +using DSharpPlus.Commands.Processors.SlashCommands; +using DSharpPlus.Commands.Processors.TextCommands; +using DSharpPlus.Commands.Processors.TextCommands.Parsing; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace DSharpPlus.Examples.Commands.Basics +{ + public static class Program + { + public static async Task Main(string[] args) + { + ConfigurationBuilder configurationBuilder = new(); + // you can also use environment vars, just uncomment this + // configurationBuilder.AddEnvironmentVariables(""); + configurationBuilder.AddJsonFile("config.json", true, true); + configurationBuilder.AddCommandLine(args); + + IConfiguration configuration = configurationBuilder.Build(); + ServiceCollection serviceCollection = new(); + serviceCollection.AddSingleton(configuration); + Assembly currentAssembly = typeof(Program).Assembly; + + serviceCollection.AddSingleton(async serviceProvider => + { + DiscordClient client = new(new DiscordConfiguration() + { + Token = configuration.GetValue("example_bot:token") ?? + throw new InvalidOperationException("Missing Discord token."), + Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents | TextCommandProcessor.RequiredIntents + }); + + CommandsExtension extension = client.UseCommands(new() + { + DebugGuildId = configuration.GetValue("example_bot:debug_guild_id", null), + ServiceProvider = serviceProvider, + + }); + await extension.AddProcessorAsync(new TextCommandProcessor()); + await extension.AddProcessorAsync(new SlashCommandProcessor()); + extension.AddCommands(currentAssembly); + + return client; + }); + IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); + + DiscordClient client = await serviceProvider.GetRequiredService>(); + await client.ConnectAsync(); + + await Task.Delay(-1); + } + } +} diff --git a/src/DSharpPlus.Examples.Commands.Basics/config.json b/src/DSharpPlus.Examples.Commands.Basics/config.json new file mode 100644 index 0000000..ba8b42b --- /dev/null +++ b/src/DSharpPlus.Examples.Commands.Basics/config.json @@ -0,0 +1,6 @@ +{ + "example_bot": { + "token": "bottoken", + "debug_guild_id": "" + } +} \ No newline at end of file diff --git a/src/DSharpPlus.Examples.CommandsNext.Basics/Commands/.editorconfig b/src/DSharpPlus.Examples.CommandsNext.Basics/Commands/.editorconfig deleted file mode 100644 index 85cd174..0000000 --- a/src/DSharpPlus.Examples.CommandsNext.Basics/Commands/.editorconfig +++ /dev/null @@ -1,5 +0,0 @@ -# .editorconfig -root = false - -[*.{cs,vb}] -dotnet_diagnostic.CA1822.severity = none # Suppress CA1822 due to CommandsNext not supporting static commands. \ No newline at end of file diff --git a/src/DSharpPlus.Examples.CommandsNext.Basics/Commands/PingCommand.cs b/src/DSharpPlus.Examples.CommandsNext.Basics/Commands/PingCommand.cs deleted file mode 100644 index 09f93c8..0000000 --- a/src/DSharpPlus.Examples.CommandsNext.Basics/Commands/PingCommand.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Text; -using System.Threading.Tasks; -using DSharpPlus.CommandsNext; -using DSharpPlus.CommandsNext.Attributes; - -namespace DSharpPlus.Examples.CommandsNext.Basics.Commands -{ - public class PingCommand : BaseCommandModule - { - [Command("ping"), Description("Checks the bot's latency to the Discord API.")] - public async Task ExecuteAsync(CommandContext context) - { - StringBuilder messageBuilder = new(); - messageBuilder.AppendLine($"Pong! Latency is {context.Client.Ping}ms."); - messageBuilder.AppendLine($"Additionally, try running {Formatter.InlineCode($"{context.Prefix}help")} to see a list of commands."); - - await context.RespondAsync(messageBuilder.ToString()); - } - } -} diff --git a/src/DSharpPlus.Examples.CommandsNext.Basics/DSharpPlus.Examples.CommandsNext.Basics.csproj b/src/DSharpPlus.Examples.CommandsNext.Basics/DSharpPlus.Examples.CommandsNext.Basics.csproj deleted file mode 100644 index f8a1bb1..0000000 --- a/src/DSharpPlus.Examples.CommandsNext.Basics/DSharpPlus.Examples.CommandsNext.Basics.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - Exe - net7.0 - enable - - - - - - \ No newline at end of file diff --git a/src/DSharpPlus.Examples.CommandsNext.Basics/Program.cs b/src/DSharpPlus.Examples.CommandsNext.Basics/Program.cs deleted file mode 100644 index 3ddd8a5..0000000 --- a/src/DSharpPlus.Examples.CommandsNext.Basics/Program.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Threading.Tasks; -using DSharpPlus.CommandsNext; - -namespace DSharpPlus.Examples.CommandsNext.Basics -{ - public static class Program - { - /// - /// The prefixes used to trigger Discord text commands through CommandsNext. - /// - private static readonly string[] _prefixes = new[] { "!" }; - - public static async Task Main() - { - // Check for token - // TODO: Load the token up from IConfiguration - string? token = Environment.GetEnvironmentVariable("DISCORD_TOKEN"); - if (string.IsNullOrWhiteSpace(token)) - { - Console.WriteLine("Please set the environment variable DISCORD_TOKEN."); - return; - } - - // Create the client - DiscordClient discord = new(new DiscordConfiguration - { - Token = token, - Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents - }); - - CommandsNextExtension commandsNext = discord.UseCommandsNext(new CommandsNextConfiguration() - { - // For brevity, we're going to use the string prefixes property. - // However, if you want to do something complicated, such as per-guild prefixes, - // you can pass a prefix resolver delegate instead. - StringPrefixes = _prefixes - }); - - // If we pass our assembly to CommandsNext, it will automatically - // search our program for any Command classes and register them on its own. - // This is very handy so you don't need to manually update a list when you add a new command. - commandsNext.RegisterCommands(typeof(Program).Assembly); - - // Connect to the Discord gateway - await discord.ConnectAsync(); - - // Wait infinitely so the bot stays connected; DiscordClient.ConnectAsync is not a blocking call - await Task.Delay(-1); - } - } -} diff --git a/src/DSharpPlus.Examples.CommandsNext.CommandArguments/DSharpPlus.Examples.CommandsNext.CommandArguments.csproj b/src/DSharpPlus.Examples.CommandsNext.CommandArguments/DSharpPlus.Examples.CommandsNext.CommandArguments.csproj index f8a1bb1..aa3e22a 100644 --- a/src/DSharpPlus.Examples.CommandsNext.CommandArguments/DSharpPlus.Examples.CommandsNext.CommandArguments.csproj +++ b/src/DSharpPlus.Examples.CommandsNext.CommandArguments/DSharpPlus.Examples.CommandsNext.CommandArguments.csproj @@ -1,11 +1,11 @@  Exe - net7.0 + net8.0 enable - - + + \ No newline at end of file diff --git a/src/DSharpPlus.Examples.CommandsNext.CustomCommandArguments/DSharpPlus.Examples.CommandsNext.CustomCommandArguments.csproj b/src/DSharpPlus.Examples.CommandsNext.CustomCommandArguments/DSharpPlus.Examples.CommandsNext.CustomCommandArguments.csproj index fedeafc..30e19ea 100644 --- a/src/DSharpPlus.Examples.CommandsNext.CustomCommandArguments/DSharpPlus.Examples.CommandsNext.CustomCommandArguments.csproj +++ b/src/DSharpPlus.Examples.CommandsNext.CustomCommandArguments/DSharpPlus.Examples.CommandsNext.CustomCommandArguments.csproj @@ -1,12 +1,12 @@  Exe - net7.0 + net8.0 enable - - + + \ No newline at end of file diff --git a/src/DSharpPlus.Examples.CommandsNext.ErrorHandling/DSharpPlus.Examples.CommandsNext.ErrorHandling.csproj b/src/DSharpPlus.Examples.CommandsNext.ErrorHandling/DSharpPlus.Examples.CommandsNext.ErrorHandling.csproj index f8a1bb1..aa3e22a 100644 --- a/src/DSharpPlus.Examples.CommandsNext.ErrorHandling/DSharpPlus.Examples.CommandsNext.ErrorHandling.csproj +++ b/src/DSharpPlus.Examples.CommandsNext.ErrorHandling/DSharpPlus.Examples.CommandsNext.ErrorHandling.csproj @@ -1,11 +1,11 @@  Exe - net7.0 + net8.0 enable - - + + \ No newline at end of file diff --git a/src/DSharpPlus.Examples.CommandsNext.GroupCommands/DSharpPlus.Examples.CommandsNext.GroupCommands.csproj b/src/DSharpPlus.Examples.CommandsNext.GroupCommands/DSharpPlus.Examples.CommandsNext.GroupCommands.csproj index fedeafc..30e19ea 100644 --- a/src/DSharpPlus.Examples.CommandsNext.GroupCommands/DSharpPlus.Examples.CommandsNext.GroupCommands.csproj +++ b/src/DSharpPlus.Examples.CommandsNext.GroupCommands/DSharpPlus.Examples.CommandsNext.GroupCommands.csproj @@ -1,12 +1,12 @@  Exe - net7.0 + net8.0 enable - - + + \ No newline at end of file diff --git a/src/DSharpPlus.Examples.Components.Buttons/DSharpPlus.Examples.Components.Buttons.csproj b/src/DSharpPlus.Examples.Components.Buttons/DSharpPlus.Examples.Components.Buttons.csproj index 1641155..22dabcd 100644 --- a/src/DSharpPlus.Examples.Components.Buttons/DSharpPlus.Examples.Components.Buttons.csproj +++ b/src/DSharpPlus.Examples.Components.Buttons/DSharpPlus.Examples.Components.Buttons.csproj @@ -1,10 +1,10 @@  Exe - net7.0 + net8.0 enable - + \ No newline at end of file diff --git a/src/DSharpPlus.Examples.Components.Modals/DSharpPlus.Examples.Components.Modals.csproj b/src/DSharpPlus.Examples.Components.Modals/DSharpPlus.Examples.Components.Modals.csproj index 1641155..22dabcd 100644 --- a/src/DSharpPlus.Examples.Components.Modals/DSharpPlus.Examples.Components.Modals.csproj +++ b/src/DSharpPlus.Examples.Components.Modals/DSharpPlus.Examples.Components.Modals.csproj @@ -1,10 +1,10 @@  Exe - net7.0 + net8.0 enable - + \ No newline at end of file diff --git a/src/DSharpPlus.Examples.Components.Selects/DSharpPlus.Examples.Components.Selects.csproj b/src/DSharpPlus.Examples.Components.Selects/DSharpPlus.Examples.Components.Selects.csproj index 1641155..22dabcd 100644 --- a/src/DSharpPlus.Examples.Components.Selects/DSharpPlus.Examples.Components.Selects.csproj +++ b/src/DSharpPlus.Examples.Components.Selects/DSharpPlus.Examples.Components.Selects.csproj @@ -1,10 +1,10 @@  Exe - net7.0 + net8.0 enable - + \ No newline at end of file