Executing Webhooks Via the Factory
If you do not have a bot client set up, you have to first add the IWebhookClientFactory
to your services:
// This goes in your ConfigureServices().
services.AddWebhookClientFactory();
With that, you'll not be able to request the factory from your service provider:
var factory = Services.GetService<IWebhookClientFactory>();
After retrieving the factory, you can now create a webhook client for the specific ID and token.
var client = factory.CreateClient(YOUR_WEBHOOK_ID, "YOUR_WEBHOOK_TOKEN");
You can also pass the webhook URL directly as there's an overload for it.
Now you can simply reuse the client
variable whenever you need to perform an action with this specific webhook.
var message = new LocalWebhookMessage()
.WithContent("Hello from a webhook!");
await client.ExecuteAsync(message);