-
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 2 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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>DSharpPlus.Examples.Commands.Basics</RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01982" /> | ||
<PackageReference Include="DSharpPlus.Commands" Version="5.0.0-nightly-01970" /> | ||
<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" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using DSharpPlus.Commands; | ||
using DSharpPlus.Commands.Processors.SlashCommands; | ||
using DSharpPlus.Commands.Processors.TextCommands; | ||
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(); | ||
configurationBuilder.Sources.Clear(); | ||
configurationBuilder.AddEnvironmentVariables(""); | ||
|
||
configurationBuilder.AddCommandLine(args); | ||
|
||
IConfiguration configuration = configurationBuilder.Build(); | ||
ServiceCollection serviceCollection = new(); | ||
serviceCollection.AddSingleton(configuration); | ||
Assembly currentAssembly = typeof(Program).Assembly; | ||
|
||
|
||
serviceCollection.AddSingleton(serviceProvider => | ||
themonarchoftime marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
DiscordClient client = new(new DiscordConfiguration() | ||
{ | ||
Token = configuration.GetValue<string>("discord:token") ?? | ||
|
||
throw new InvalidOperationException("Missing Discord token."), | ||
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents | ||
themonarchoftime marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}); | ||
|
||
CommandsExtension extension = client.UseCommands(new() | ||
{ | ||
DebugGuildId = configuration.GetValue<ulong?>("discord:debug_guild_id", null), | ||
ServiceProvider = serviceProvider, | ||
}); | ||
|
||
extension.AddProcessorAsync(new TextCommandProcessor()); | ||
extension.AddProcessorAsync(new SlashCommandProcessor()); | ||
extension.AddCommands(currentAssembly); | ||
|
||
return client; | ||
}); | ||
IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); | ||
|
||
DiscordClient client = serviceProvider.GetRequiredService<DiscordClient>(); | ||
await client.ConnectAsync(); | ||
|
||
await Task.Delay(-1); | ||
} | ||
} | ||
} |
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> |
Uh oh!
There was an error while loading. Please reload this page.