C
C#15mo ago
Elmishh

❔ how do i use discord webhooks in a console app?

title
17 Replies
Thinker
Thinker15mo ago
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
Thinker
Thinker15mo ago
You just send a post request to the webhook url with the content as JSON in the body of the request.
Thinker
Thinker15mo ago
Thinker
Thinker15mo ago
There are probably also some webhook libraries already made for C# Minimal example:
var client = new HttpClient();
var webhookUrl = "https://discord.com/api/webhooks/123123123/abcdefghijklmnopqrstuvwxyz";
await client.PostAsJsonAsync(webhookUrl, new WebhookContent("Hello world!"));

record WebhookContent(string Content);
var client = new HttpClient();
var webhookUrl = "https://discord.com/api/webhooks/123123123/abcdefghijklmnopqrstuvwxyz";
await client.PostAsJsonAsync(webhookUrl, new WebhookContent("Hello world!"));

record WebhookContent(string Content);
(obviously you should replace the webhookUrl string with your actual webhook URL)
Azrael
Azrael15mo ago
Records!
Elmishh
ElmishhOP15mo ago
ty btw what does record WebhookContent(string Content); do? oh i realize what is a record
Thinker
Thinker15mo ago
It's like a class, but it only has one property called Content
Elmishh
ElmishhOP15mo ago
figured it out thanks
Thinker
Thinker15mo ago
You could replace it with this instead if you wanted to
class WebhookContent
{
public string Content { get; set; }

public WebhookContent(string content)
{
Content = content;
}
}
class WebhookContent
{
public string Content { get; set; }

public WebhookContent(string content)
{
Content = content;
}
}
Elmishh
ElmishhOP15mo ago
The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.
Kouhai
Kouhai15mo ago
Yes, you can only await a Task<T> inside an async method
Elmishh
ElmishhOP15mo ago
that doesnt tell me much
Kouhai
Kouhai15mo ago
What does your code look like?
Elmishh
ElmishhOP15mo ago
Kouhai
Kouhai15mo ago
SendMessage needs to be async async Task SendMessage
Elmishh
ElmishhOP15mo ago
alright ty
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server