-
Notifications
You must be signed in to change notification settings - Fork 34
Switch to Commands for basic example #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.0.0
Are you sure you want to change the base?
Changes from all commits
33dea9b
98674db
c3aa229
09af9a1
c50e6ff
3162da3
5919300
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01970" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01970" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>DSharpPlus.Examples.Commands.Basics</RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Include="./config.json" CopyToOutputDirectory="PreserveNewest" /> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01982" /> | ||
<PackageReference Include="DSharpPlus.Commands" Version="5.0.0-nightly-01982" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string>("example_bot:token") ?? | ||
throw new InvalidOperationException("Missing Discord token."), | ||
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents | TextCommandProcessor.RequiredIntents | ||
}); | ||
|
||
CommandsExtension extension = client.UseCommands(new() | ||
{ | ||
DebugGuildId = configuration.GetValue<ulong?>("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<Task<DiscordClient>>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this async There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. asked by lunar in last review There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OoLunar why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #13 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this is intended. Adding processors is an asynchronous operation. Encouraging There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would do the whole setup outside the |
||
await client.ConnectAsync(); | ||
|
||
await Task.Delay(-1); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"example_bot": { | ||
"token": "bottoken", | ||
"debug_guild_id": "" | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01970" /> | ||
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01970" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01970" /> | ||
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01970" /> | ||
<PackageReference Include="Ulid" Version="1.3.3" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01970" /> | ||
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01970" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01970" /> | ||
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01970" /> | ||
<PackageReference Include="Ulid" Version="1.3.3" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01970" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01970" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01788" /> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01970" /> | ||
</ItemGroup> | ||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// right click on config.json, click properties, and in Copy to Output Directory select Copy if newer