Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions Example-Bots.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +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}"
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
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Examples.CommandsNext.CustomCommandArguments", "src\DSharpPlus.Examples.CommandsNext.CustomCommandArguments\DSharpPlus.Examples.CommandsNext.CustomCommandArguments.csproj", "{9424B2A1-C411-4B1E-A0C3-48CAA91CDC4B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Examples.CommandsNext.ErrorHandling", "src\DSharpPlus.Examples.CommandsNext.ErrorHandling\DSharpPlus.Examples.CommandsNext.ErrorHandling.csproj", "{6E106DAA-D075-4AD2-AA10-41327B9D3FF4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Examples.CommandsNext.GroupCommands", "src\DSharpPlus.Examples.CommandsNext.GroupCommands\DSharpPlus.Examples.CommandsNext.GroupCommands.csproj", "{5A3B56EC-DD5E-4D15-859B-94B09ADC2795}"
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -64,22 +56,6 @@ Global
{7135C15F-A8FD-4CEB-BA07-ED45FFBFFFF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7135C15F-A8FD-4CEB-BA07-ED45FFBFFFF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7135C15F-A8FD-4CEB-BA07-ED45FFBFFFF5}.Release|Any CPU.Build.0 = Release|Any CPU
{1159DF74-2834-4A7B-97C2-384C8578F6A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1159DF74-2834-4A7B-97C2-384C8578F6A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1159DF74-2834-4A7B-97C2-384C8578F6A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1159DF74-2834-4A7B-97C2-384C8578F6A6}.Release|Any CPU.Build.0 = Release|Any CPU
{9424B2A1-C411-4B1E-A0C3-48CAA91CDC4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9424B2A1-C411-4B1E-A0C3-48CAA91CDC4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9424B2A1-C411-4B1E-A0C3-48CAA91CDC4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9424B2A1-C411-4B1E-A0C3-48CAA91CDC4B}.Release|Any CPU.Build.0 = Release|Any CPU
{6E106DAA-D075-4AD2-AA10-41327B9D3FF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6E106DAA-D075-4AD2-AA10-41327B9D3FF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6E106DAA-D075-4AD2-AA10-41327B9D3FF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6E106DAA-D075-4AD2-AA10-41327B9D3FF4}.Release|Any CPU.Build.0 = Release|Any CPU
{5A3B56EC-DD5E-4D15-859B-94B09ADC2795}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A3B56EC-DD5E-4D15-859B-94B09ADC2795}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A3B56EC-DD5E-4D15-859B-94B09ADC2795}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A3B56EC-DD5E-4D15-859B-94B09ADC2795}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{43280D9F-9965-4270-9082-12029948F559} = {1DE5170D-7FE0-487D-9EAF-5327832D8A4B}
Expand All @@ -89,9 +65,5 @@ Global
{00471D68-8D82-469D-959F-1B6058248A15} = {1DE5170D-7FE0-487D-9EAF-5327832D8A4B}
{C5197139-4026-4EE9-A301-136FC3E10DA3} = {1DE5170D-7FE0-487D-9EAF-5327832D8A4B}
{7135C15F-A8FD-4CEB-BA07-ED45FFBFFFF5} = {1DE5170D-7FE0-487D-9EAF-5327832D8A4B}
{1159DF74-2834-4A7B-97C2-384C8578F6A6} = {1DE5170D-7FE0-487D-9EAF-5327832D8A4B}
{9424B2A1-C411-4B1E-A0C3-48CAA91CDC4B} = {1DE5170D-7FE0-487D-9EAF-5327832D8A4B}
{6E106DAA-D075-4AD2-AA10-41327B9D3FF4} = {1DE5170D-7FE0-487D-9EAF-5327832D8A4B}
{5A3B56EC-DD5E-4D15-859B-94B09ADC2795} = {1DE5170D-7FE0-487D-9EAF-5327832D8A4B}
EndGlobalSection
EndGlobal
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,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" Version="5.0.0-nightly-01970" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
Expand Down
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>
13 changes: 13 additions & 0 deletions src/DSharpPlus.Examples.Commands.Basics/Commands/PingCommand.cs
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-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" />
</ItemGroup>
</Project>
55 changes: 55 additions & 0 deletions src/DSharpPlus.Examples.Commands.Basics/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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();
configurationBuilder.AddEnvironmentVariables("");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is, at a glance, rather questionable. we should also probably encourage a config file to at least be considered

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config files... For an example bot? The purpose of an example bot is to demonstrate how to do XYZ while being easy to setup and run.

Also I think this might throw, if it hasn't been tested

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>("discord:token") ??
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider renaming "discord" in the eaxmples to "example-bot", to make clear what this identifier is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's grabbing the discord token from the discord property:

{
   "discord":
   {
        "token": "invalid"
    }
}

throw new InvalidOperationException("Missing Discord token."),
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents | TextCommandProcessor.RequiredIntents
});

CommandsExtension extension = client.UseCommands(new()
{
DebugGuildId = configuration.GetValue<ulong?>("discord: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>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this async

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asked by lunar in last review

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OoLunar why

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#13 (comment)
i think this comment is meant which was to a different part of the code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is intended. Adding processors is an asynchronous operation. Encouraging .GetAwaiter().GetResult() goes against everything I've worked on within the lib, especially when it's done on ValueTasks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do the whole setup outside the AddSinglton and then add the client

await client.ConnectAsync();

await Task.Delay(-1);
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

52 changes: 0 additions & 52 deletions src/DSharpPlus.Examples.CommandsNext.Basics/Program.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading