Skip to content
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

[Docs] Improve IntFw intro demo code #2829

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all 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: 27 additions & 3 deletions docs/guides/int_framework/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,36 @@ To start using the Interaction Service, you need to create a service instance.
Optionally you can provide the [InteractionService] constructor with a
[InteractionServiceConfig] to change the services behaviour to suit your needs.

The following is based on the [Text-based Command starter code](xref:Guides.TextCommands.Intro#get-started)
```csharp
...
// _client here is DiscordSocketClient.
// A different approach to passing in a restclient is also possible.
var _interactionService = new InteractionService(_client.Rest);
public class Program
{
private DiscordSocketClient _bot = new();
private InteractionService _svc = new(_bot);

private static async Task SlashCmdExecutedHandler(SocketSlashCommand cmd)
{
var ctx = new SocketInteractionContext(_bot, cmd);
await _svc_.ExecuteCommandAsync(ctx, null); // Magically executes SayHiAsync (Or other SlashCommand you defined)
}

// Call me in some other init methods to register all cmd handler classes!
public async Task InitServiceAsync()
{
_bot.SlashCommandExecuted += SlashCmdExecutedHandler;
await _svc.AddModulesAsync(Assembly.GetEntryAssembly(), null);
}
}

public class CmdHandlers : InteractionModuleBase
{
[SlashCommand("Hi", "Say hi")]
public async Task SayHiAsync()
{
await RespondAsync("Hi");
}
}
...
```

Expand Down