Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Example-Bots.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
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>
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-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>
56 changes: 56 additions & 0 deletions src/DSharpPlus.Examples.Commands.Basics/Program.cs
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("");
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(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
});

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.

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

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>