Skip to content

Jodenee/Sharphook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sharphook

Overview

Sharphook is an asynchronous object oriented API wrapper for Discord's webhook API.

Installation

.NET Compatibility

.NET Version Compatible?
.NET 8 YES
.NET 7 YES
.NET 6 YES
.NET 5 NO
.NET 3.1 NO
.NET 3.0 NO
.NET 2.2 NO
.NET 2.1 NO
.NET 2.0 NO
.NET 1.1 NO
.NET 1.0 NO

Instructions

  • Go to releases
  • Find the latest version
  • Download the folder with your .NET version
  • Unzip the folder
  • Add Sharphook.dll as a reference to your project

(Nuget support coming in v1.0.0)

Examples

Sending a message

WebhookClient webhookClient = new WebhookClient();
PartialWebhook webhook = webhookClient.GetPartialWebhook(123, "Token");

await webhook.SendMessageAsync("Hello, world!");

Sending a message to a thread

WebhookClient webhookClient = new WebhookClient();
PartialWebhook webhook = webhookClient.GetPartialWebhook(123, "Token");
ulong threadId = 123;

await webhook.SendMessageInThreadAsync(threadId, "Hello, world!");

Obtaining a message object

WebhookClient webhookClient = new WebhookClient();
PartialWebhook webhook = webhookClient.GetPartialWebhook(123, "Token");

Message message = await webhook.SendMessageAsync("Hello, world!", null, true);

Console.WriteLine(message.Id);

Editing a webhook

WebhookClient webhookClient = new WebhookClient();
PartialWebhook webhook = webhookClient.GetPartialWebhook(123, "Token");

// Edit webhook name
await webhook.EditNameAsync("New name");

// Edit webhook avatar
await webhook.EditAvatarAsync(@"newAvatar.png", ImageFormat.Png);

Error handling

WebhookClient webhookClient = new WebhookClient();
PartialWebhook webhook = webhookClient.GetPartialWebhook(123, "Token");
ulong threadId = 123;
ulong messageId = 456;

try
{
    await webhook.DeleteMessageInThreadAsync(
        threadId,
        messageId
    );
}
catch (NotFound)
{
    Console.WriteLine("Thread or message wasn't found.");
}

License

Sharphook is under the MIT license.

Disclaimers

  • Sharphook is just maintained for fun.
  • Sharphook is in pre-release.