C
C#10mo ago
TakingYourGF

how to make this into a embed message with webhook

SendDiscordWebhook(true, string.Format("{0} Was Killed By {1} And Now Has {2} Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
175 Replies
Angius
Angius10mo ago
Idk, what Discord library are you using? It should have some Embed class you can send instead of a string (also, use $interpolation instead of format)
MODiX
MODiX10mo ago
String interpolation is the preferred way of building strings in C#. It is easier to read than concatenation. For example:
var foo = 1;
var bar = 2;
Console.WriteLine("foo is equal to: " + foo + " and bar is equal to: " + bar);
var foo = 1;
var bar = 2;
Console.WriteLine("foo is equal to: " + foo + " and bar is equal to: " + bar);
can be written as:
var foo = 1;
var bar = 2;
Console.WriteLine($"foo is equal to: {foo} and bar is equal to: {bar}");
var foo = 1;
var bar = 2;
Console.WriteLine($"foo is equal to: {foo} and bar is equal to: {bar}");
TakingYourGF
TakingYourGFOP10mo ago
if (!string.IsNullOrEmpty(Settings.KillFeedWebhookUrl) && Settings.DiscordKillFeed) { //kills logging (discord) string kill = packet.Message; if (ikill.Contains("killed") && !ikill.Contains("cactus") && !ikill.Contains("Collision")) { string[] killinfo = ParseAndFilterKill(ikill); if (kill_info[0] != "A Scientist") { if (IsAllNumbers(kill_info[1])) kill_info[1] = "A Scientist"; SendDiscordWebhook(true, string.Format("{0} Was Killed By {1} And Now Has {2} Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0]))); } else SendDiscordWebhook(true, string.Format("{0} Was Killed By {1}", kill_info[0], ReplaceDeathText(killinfo[1], replacements))); } else if (kill.Contains("died")) { if (!kill.Contains("died (Generic)") || !kill.Contains("died (Collision)")) { string[] deathinfo = ParseDeath(ikill); if (!death_info[1].ToLower().Contains("collision") || !death_info[1].ToLower().Contains("generic")) { SendDiscordWebhook(true, string.Format("{0} Died By {1} And Now Has {2} Deaths!", death_info[0], ReplaceDeathText(death_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(death_info[0]))); } } } } this is my whole message thing right now it just sends plain
Angius
Angius10mo ago
$code
MODiX
MODiX10mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
if (!string.IsNullOrEmpty(Settings.KillFeedWebhookUrl) && Settings.DiscordKillFeed) {
//kills logging (discord)
string kill = packet.Message;
if (ikill.Contains("killed") && !ikill.Contains("cactus") && !ikill.Contains("Collision"))
{
string[] killinfo = ParseAndFilterKill(ikill);
if (killinfo[0] != "A Scientist")
{
if (IsAllNumbers(kill_info[1]))
kill_info[1] = "A Scientist";
SendDiscordWebhook(true, string.Format("{0} Was Killed By {1} And Now Has {2} Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
}
else
SendDiscordWebhook(true, string.Format("{0} Was Killed By {1}", kill_info[0], ReplaceDeathText(kill_info[1], replacements)));
}
else if (kill.Contains("died"))
{
if (!kill.Contains("died (Generic)") || !kill.Contains("died (Collision)"))
{
string[] deathinfo = ParseDeath(ikill);
if (!death_info[1].ToLower().Contains("collision") || !death_info[1].ToLower().Contains("generic"))
{
SendDiscordWebhook(true, string.Format("{0} Died By {1} And Now Has {2} Deaths!", death_info[0], ReplaceDeathText(death_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(death_info[0])));
}
}
}
}
if (!string.IsNullOrEmpty(Settings.KillFeedWebhookUrl) && Settings.DiscordKillFeed) {
//kills logging (discord)
string kill = packet.Message;
if (ikill.Contains("killed") && !ikill.Contains("cactus") && !ikill.Contains("Collision"))
{
string[] killinfo = ParseAndFilterKill(ikill);
if (killinfo[0] != "A Scientist")
{
if (IsAllNumbers(kill_info[1]))
kill_info[1] = "A Scientist";
SendDiscordWebhook(true, string.Format("{0} Was Killed By {1} And Now Has {2} Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
}
else
SendDiscordWebhook(true, string.Format("{0} Was Killed By {1}", kill_info[0], ReplaceDeathText(kill_info[1], replacements)));
}
else if (kill.Contains("died"))
{
if (!kill.Contains("died (Generic)") || !kill.Contains("died (Collision)"))
{
string[] deathinfo = ParseDeath(ikill);
if (!death_info[1].ToLower().Contains("collision") || !death_info[1].ToLower().Contains("generic"))
{
SendDiscordWebhook(true, string.Format("{0} Died By {1} And Now Has {2} Deaths!", death_info[0], ReplaceDeathText(death_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(death_info[0])));
}
}
}
}
TakingYourGF
TakingYourGFOP10mo ago
i have it sending like this i wanna make this message from what i got into a embed message
No description
MODiX
MODiX10mo ago
Angius
Idk, what Discord library are you using?
React with ❌ to remove this embed.
Angius
Angius10mo ago
If none, what's SendDiscordWebhook?
TakingYourGF
TakingYourGFOP10mo ago
trying to make it look like this
No description
Angius
Angius10mo ago
I KNOW what embeds are Answer my questions
TakingYourGF
TakingYourGFOP10mo ago
static void SendDiscordWebhook(bool killfeed, string message)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Settings = Settings.Read();
using (var client = new WebClient())
{
var data = new NameValueCollection();
data["content"] = string.Format("{0}{1}", message, Environment.NewLine);
var response = client.UploadValues(killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl, "POST", data);
string responseText = Encoding.UTF8.GetString(response);
}
}
static void SendDiscordWebhook(bool killfeed, string message)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Settings = Settings.Read();
using (var client = new WebClient())
{
var data = new NameValueCollection();
data["content"] = string.Format("{0}{1}", message, Environment.NewLine);
var response = client.UploadValues(killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl, "POST", data);
string responseText = Encoding.UTF8.GetString(response);
}
}
aint using a discord library
Angius
Angius10mo ago
I see, yes Give me a moment
TakingYourGF
TakingYourGFOP10mo ago
thanks brother im new to the whole discord shit lolol
Angius
Angius10mo ago
So, first we need to hit up the docs to see what an embed object is: https://discord.com/developers/docs/resources/channel#embed-object And how to execute webhooks: https://discord.com/developers/docs/resources/webhook#execute-webhook
TakingYourGF
TakingYourGFOP10mo ago
yeah i was looking at these already
Angius
Angius10mo ago
Now we know we need to send JSON data that looks like
{
"embeds": [
{
"title": "My Cool Embed",
"description": "The coolest one",
"color": 0xFF0000
}
]
}
{
"embeds": [
{
"title": "My Cool Embed",
"description": "The coolest one",
"color": 0xFF0000
}
]
}
Easiest way, is to make classes (or records) that represent this structure, create those objects, serialize it to JSON, and send that
record WebhookMessage(Embed[] Embeds);
record Embed(string Title, string Description, int Color);
record WebhookMessage(Embed[] Embeds);
record Embed(string Title, string Description, int Color);
var data = new WebhookMessage(new Embed[]{
new("My Cool Embed", "The coolest one", 0xFF0000),
});

using var client = new HttpClient();
var response = await client.PostAsJsonAsync(url, data);
var data = new WebhookMessage(new Embed[]{
new("My Cool Embed", "The coolest one", 0xFF0000),
});

using var client = new HttpClient();
var response = await client.PostAsJsonAsync(url, data);
(notice my use of HttpClient, since WebClient is long since deprecated)
TakingYourGF
TakingYourGFOP10mo ago
yeah i dont understand how i would make what i have into a embed lol
Angius
Angius10mo ago
private static readonly _client = new HttpClient();

static async Task SendDiscordWebhook(bool killfeed, string message)
{
var data = new WebhookMessage(new Embed[]{
new("Your Killfeed", message, 0xFF0000),
});

var response = await _client.PostAsJsonAsync(url, data);
}
private static readonly _client = new HttpClient();

static async Task SendDiscordWebhook(bool killfeed, string message)
{
var data = new WebhookMessage(new Embed[]{
new("Your Killfeed", message, 0xFF0000),
});

var response = await _client.PostAsJsonAsync(url, data);
}
Or, well, any other data you want to include
TakingYourGF
TakingYourGFOP10mo ago
yeah im losted nvm lol just gonna pay someone a dev or someshit to covert it to embed lol so i can see how its done
Angius
Angius10mo ago
What you send to a webhook is a JSON payload Whether it's a plain message, an embed, or anything else Right now, in your code, you're using a very 1998 way of sending a plain message For something more complex, like an embed object, it's better to use... an object And serialize it
TakingYourGF
TakingYourGFOP10mo ago
would rather just have someone covert it for me to embed and etc lool cuz this shit got me lost asf
Angius
Angius10mo ago
Sure, if you'd rather pay
TakingYourGF
TakingYourGFOP10mo ago
yeah i will pay idc lolol
Angius
Angius10mo ago
I prefer learning, but to each their own
TakingYourGF
TakingYourGFOP10mo ago
yeah im lost asf tho how to chnge it all to make it okr work
Angius
Angius10mo ago
Instead of sending a simple "unga killed bunga" string, you need to send a properly structured JSON string like "{"embeds:[{"title":"title","description":"desc","color":18283}]"}" That's the change
MODiX
MODiX10mo ago
Sorry @TakingYourGF your message contained blocked content and has been removed! Sorry @TakingYourGF your message contained blocked content and has been removed!
TakingYourGF
TakingYourGFOP10mo ago
//item logging
string itemmsg = packet.Message;
if (itemmsg.Contains("[ServerVar] giving"))
{
if (!string.IsNullOrEmpty(Settings.ItemWebhookUrl))
{
string pattern = @"\[ServerVar\] giving (\w+) (\d+) x (\w+)";
Match match = Regex.Match(itemmsg, pattern);

if (match.Success)
{
SendDiscordWebhookItem(string.Format("**{0}** Has Recieved ***{1}*** ({2})", match.Groups[1].Value, match.Groups[3].Value, int.Parse(match.Groups[2].Value)));
}
else
{
string pattern2 = @"\[ServerVar\] giving (\w+) (\d+) x (.+)";

Match match2 = Regex.Match(itemmsg, pattern2);
if (match2.Success)
{
SendDiscordWebhookItem(string.Format("**{0}** Has Recieved ***{1}*** ({2})", match2.Groups[1].Value, match2.Groups[3].Value, int.Parse(match2.Groups[2].Value)));
}
}
}
}
//item logging
string itemmsg = packet.Message;
if (itemmsg.Contains("[ServerVar] giving"))
{
if (!string.IsNullOrEmpty(Settings.ItemWebhookUrl))
{
string pattern = @"\[ServerVar\] giving (\w+) (\d+) x (\w+)";
Match match = Regex.Match(itemmsg, pattern);

if (match.Success)
{
SendDiscordWebhookItem(string.Format("**{0}** Has Recieved ***{1}*** ({2})", match.Groups[1].Value, match.Groups[3].Value, int.Parse(match.Groups[2].Value)));
}
else
{
string pattern2 = @"\[ServerVar\] giving (\w+) (\d+) x (.+)";

Match match2 = Regex.Match(itemmsg, pattern2);
if (match2.Success)
{
SendDiscordWebhookItem(string.Format("**{0}** Has Recieved ***{1}*** ({2})", match2.Groups[1].Value, match2.Groups[3].Value, int.Parse(match2.Groups[2].Value)));
}
}
}
}
if i wanted to change this to embed could you show me a full exmaple of this one so ik what i should be doing and changing and etc
Angius
Angius10mo ago
Changing your SendDiscordWebhook message to this
TakingYourGF
TakingYourGFOP10mo ago
static void SendDiscordWebhookItem(string message)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Settings = Settings.Read();
using (var client = new WebClient())
{
var data = new NameValueCollection();
data["content"] = message;
var response = client.UploadValues(Settings.ItemWebhookUrl, "POST", data);
string responseText = Encoding.UTF8.GetString(response);
}
}
static void SendDiscordWebhookItem(string message)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Settings = Settings.Read();
using (var client = new WebClient())
{
var data = new NameValueCollection();
data["content"] = message;
var response = client.UploadValues(Settings.ItemWebhookUrl, "POST", data);
string responseText = Encoding.UTF8.GetString(response);
}
}
so i would full on change this? to what you sent me
Angius
Angius10mo ago
Or, let's make it more understandable maybe
class WebhookMessage
{
public required Embed[] Embeds { get; init; }
}
class Embed
{

public required string Title { get; init; }
public required string Message { get; init; }
public required int color { get; init; }
}
class WebhookMessage
{
public required Embed[] Embeds { get; init; }
}
class Embed
{

public required string Title { get; init; }
public required string Message { get; init; }
public required int color { get; init; }
}
class DiscordSenderOrWhatever
{
private static readonly _client = new HttpClient();

static async Task SendDiscordWebhook(bool killfeed, string title, string message)
{
var data = new WebhookMessage {
Embeds = new[]{
new Embed {
Title = title,
Message = message,
Color = 0xFF0000 // red
}
}
};

var response = await _client.PostAsJsonAsync(url, data);
}
}
class DiscordSenderOrWhatever
{
private static readonly _client = new HttpClient();

static async Task SendDiscordWebhook(bool killfeed, string title, string message)
{
var data = new WebhookMessage {
Embeds = new[]{
new Embed {
Title = title,
Message = message,
Color = 0xFF0000 // red
}
}
};

var response = await _client.PostAsJsonAsync(url, data);
}
}
To this method you would pass whatever else you want to be a part of the embed And to the Embed class you would add whatever other properties you need According to the Discord documentation HttpClient is used instead of WebClient because WebClient is deprecated And we only use a single static instance of it, because creating new clients can lead to issues (port exhaustion) So we want to reuse it Then we use PostAsJsonAsync(), a convenience method that automatically serializes the data we send into a JSON string and sends it It also sets appropriate headers
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
so i want something like this
Angius
Angius10mo ago
Yes, that would describe your message structure
TakingYourGF
TakingYourGFOP10mo ago
do i need a library ? to add
Angius
Angius10mo ago
To add what?
TakingYourGF
TakingYourGFOP10mo ago
cuz i see alot of the red lnes
Angius
Angius10mo ago
Yeah, idk why Where did you place the code? And what do the errors say?
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
under my form1 with all my other classes
Angius
Angius10mo ago
Ah, huh, I would guess you're using an outdated version of .NET? Remove the required then and turn init into set
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
okay now what
Angius
Angius10mo ago
Now look at the rest of my code Admittedly, I haven't worked with Winforms or with outdated versions of .NET for quite a while, so it might not 100% work either
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
And the errors this time are?
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
Ah, whoops
private static readonly HttpClient _client = new HttpClient();
private static readonly HttpClient _client = new HttpClient();
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
And, yeah, you supply the URL Your webhook URL to be precise
TakingYourGF
TakingYourGFOP10mo ago
okay so wait i have it so you put the webhook inside another file a config file
Angius
Angius10mo ago
Yeah, it would be best to not hardcode it
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
i have it in a config file
Angius
Angius10mo ago
Cool
TakingYourGF
TakingYourGFOP10mo ago
config.json
Angius
Angius10mo ago
Read it from the config and pass it as the url
TakingYourGF
TakingYourGFOP10mo ago
var response = client.UploadValues(killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl, "POST", data); this is what i got atm
var data = new NameValueCollection();
data["content"] = string.Format("{0}{1}", message, Environment.NewLine);
var response = client.UploadValues(killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl, "POST", data);
string responseText = Encoding.UTF8.GetString(response);
var data = new NameValueCollection();
data["content"] = string.Format("{0}{1}", message, Environment.NewLine);
var response = client.UploadValues(killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl, "POST", data);
string responseText = Encoding.UTF8.GetString(response);
Angius
Angius10mo ago
Looks like killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl would decide your webhook URL then
TakingYourGF
TakingYourGFOP10mo ago
cs

var response = await _client.PostAsJsonAsync(killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl, data);
cs

var response = await _client.PostAsJsonAsync(killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl, data);
so it should look like this
Angius
Angius10mo ago
Yeah
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
You need to reference System.Http.Json namespace, IIRC So add a using Sytem.Http.Json; reference at the top of the file Assuming your version of .NET has that
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
Sorry, System.Net.Http.Json
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
wrong lolol
Angius
Angius10mo ago
Json not json
TakingYourGF
TakingYourGFOP10mo ago
either works lol
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
Ah, yeah, guess it's not there In that case,
var response = await _client.PostAsJsonAsync(url, data);
var response = await _client.PostAsJsonAsync(url, data);
needs to become
var content = new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json");
var response = await _client.PostAsync(url, content);
var content = new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json");
var response = await _client.PostAsync(url, content);
Assuming... your version of .NET has System.Text.Json namespace
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
What's the error on Serialize?
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
I guess that's Newtonsoft...? That's why I diteched old versions long ago lmao Try SerializeObject? Instead of Serialize
TakingYourGF
TakingYourGFOP10mo ago
nope
Angius
Angius10mo ago
JsonConvert.SerializeObject(data)...?
TakingYourGF
TakingYourGFOP10mo ago
that worked lol
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
Looks right ?
Angius
Angius10mo ago
I think so, yeah
TakingYourGF
TakingYourGFOP10mo ago
okay so this is done now what?
Angius
Angius10mo ago
Now use this method to send an embed
TakingYourGF
TakingYourGFOP10mo ago
if (!string.IsNullOrEmpty(Settings.KillFeedWebhookUrl) && Settings.DiscordKillFeed) {
//kills logging (discord)
string kill_ = packet.Message;
if (ikill_.Contains("killed") && !ikill_.Contains("cactus") && !ikill_.Contains("Collision"))
{
string[] kill_info = ParseAndFilterKill(ikill_);
if (kill_info[0] != "A Scientist")
{
if (IsAllNumbers(kill_info[1]))
kill_info[1] = "A Scientist";
SendDiscordWebhook(true, string.Format("**{0}** Was Killed By **{1}** And Now Has **{2}** Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
}
else
SendDiscordWebhook(true, string.Format("**{0}** Was Killed By **{1}**", kill_info[0], ReplaceDeathText(kill_info[1], replacements)));
}
else if (kill_.Contains("died"))
{
if (!kill_.Contains("died (Generic)") || !kill_.Contains("died (Collision)"))
{
string[] death_info = ParseDeath(ikill_);
if (!death_info[1].ToLower().Contains("collision") || !death_info[1].ToLower().Contains("generic"))
{
SendDiscordWebhook(true, string.Format("**{0}** Died By **{1}** And Now Has **{2}** Deaths!", death_info[0], ReplaceDeathText(death_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(death_info[0])));
}
}
}
}
if (!string.IsNullOrEmpty(Settings.KillFeedWebhookUrl) && Settings.DiscordKillFeed) {
//kills logging (discord)
string kill_ = packet.Message;
if (ikill_.Contains("killed") && !ikill_.Contains("cactus") && !ikill_.Contains("Collision"))
{
string[] kill_info = ParseAndFilterKill(ikill_);
if (kill_info[0] != "A Scientist")
{
if (IsAllNumbers(kill_info[1]))
kill_info[1] = "A Scientist";
SendDiscordWebhook(true, string.Format("**{0}** Was Killed By **{1}** And Now Has **{2}** Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
}
else
SendDiscordWebhook(true, string.Format("**{0}** Was Killed By **{1}**", kill_info[0], ReplaceDeathText(kill_info[1], replacements)));
}
else if (kill_.Contains("died"))
{
if (!kill_.Contains("died (Generic)") || !kill_.Contains("died (Collision)"))
{
string[] death_info = ParseDeath(ikill_);
if (!death_info[1].ToLower().Contains("collision") || !death_info[1].ToLower().Contains("generic"))
{
SendDiscordWebhook(true, string.Format("**{0}** Died By **{1}** And Now Has **{2}** Deaths!", death_info[0], ReplaceDeathText(death_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(death_info[0])));
}
}
}
}
how would i make this work?
Angius
Angius10mo ago
What doesn't work about it?
TakingYourGF
TakingYourGFOP10mo ago
wait confused should i try it lol?
static void SendDiscordWebhook(bool killfeed, string message)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Settings = Settings.Read();
using (var client = new WebClient())
{
var data = new NameValueCollection();
data["content"] = string.Format("{0}{1}", message, Environment.NewLine);
var response = client.UploadValues(killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl, "POST", data);
string responseText = Encoding.UTF8.GetString(response);
}
}
static void SendDiscordWebhook(bool killfeed, string message)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Settings = Settings.Read();
using (var client = new WebClient())
{
var data = new NameValueCollection();
data["content"] = string.Format("{0}{1}", message, Environment.NewLine);
var response = client.UploadValues(killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl, "POST", data);
string responseText = Encoding.UTF8.GetString(response);
}
}
should i delete this one now? or what?
Angius
Angius10mo ago
Keep it
TakingYourGF
TakingYourGFOP10mo ago
ok
Angius
Angius10mo ago
I don't suppose you have version control set up, so keep it just in case
TakingYourGF
TakingYourGFOP10mo ago
so how would i make the stuff use the embed now?
Angius
Angius10mo ago
You would call the new method instead of the old one I guess make it static
TakingYourGF
TakingYourGFOP10mo ago
like what would i replace? so ik
Angius
Angius10mo ago
And use
await DiscordSenderOrWhatever.SendDiscordWebhook(bla, bla, bla)
await DiscordSenderOrWhatever.SendDiscordWebhook(bla, bla, bla)
Instead of your current method Ah, I don't suppose the calling method is asynchronous... you mentioned it's winforms, right? Fuck it then,
DiscordSenderOrWhatever.SendDiscordWebhook(bla, bla, bla).GetAwaiter().GetResult();
DiscordSenderOrWhatever.SendDiscordWebhook(bla, bla, bla).GetAwaiter().GetResult();
Sorry, I'm unwilling to delve into explaining what asynchronous code is and how to make it work with Winforms now lol
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
would i just do this?
Angius
Angius10mo ago
For example, yes Ideally after solving the errors, whatever they are
TakingYourGF
TakingYourGFOP10mo ago
SendDiscordWebhook(true, string.Format("**{0}** Was Killed By **{1}** And Now Has **{2}** Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
SendDiscordWebhook(true, string.Format("**{0}** Was Killed By **{1}** And Now Has **{2}** Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
this is where it sends it so how would i make it use the embed instea
Angius
Angius10mo ago
What do you mean Like this
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
The method will take whatever you need to be inside of the embed Make sure you have the namespace referenced Right now, it will send an embed with title, description, and color If you need anything more in that embed, add it according to the Discord documentation And pass the required data
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
Ah, make sure the class is public And, ideally, have it in a separate file Nor as a nested class of the Form1 class
TakingYourGF
TakingYourGFOP10mo ago
should i just make a full new class for the discordSenderOrwhatever
Angius
Angius10mo ago
The convention is that every class has its own file, yes
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
fuck me
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
See how you had it done in your original method You had Settings = new Settings() right?
TakingYourGF
TakingYourGFOP10mo ago
yeah
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
its not even locked lol
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
fixed one error goes into antoher one
Angius
Angius10mo ago
Make the method public
TakingYourGF
TakingYourGFOP10mo ago
it is lolol
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
What's the full error? Can you try quick fixes?
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
trying it now
Angius
Angius10mo ago
Ah, well, if you say that a method takes some parameter, you need to give it that parameter C# 101 The method takes a bool a string with the title of the embed, and a string with the body of the embed
TakingYourGF
TakingYourGFOP10mo ago
yeah that didnt work lol
Angius
Angius10mo ago
Give it true, "whatever title", string.Format(...... as the parameters
TakingYourGF
TakingYourGFOP10mo ago
wait wym im confused
EmbedDiscord.DiscordSenderOrWhatever.SendDiscordWebhook(true, string.Format("**{0}** Was Killed By **{1}** And Now Has **{2}** Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
EmbedDiscord.DiscordSenderOrWhatever.SendDiscordWebhook(true, string.Format("**{0}** Was Killed By **{1}** And Now Has **{2}** Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
this is what i got right now
Angius
Angius10mo ago
Yeah, you give this method two parameters And it wants three parameters I... think you give it two, string.Format() kinda makes it unclear Two is not three
TakingYourGF
TakingYourGFOP10mo ago
so what should i do lol confused asf
MODiX
MODiX10mo ago
Angius
Give it true, "whatever title", string.Format(...... as the parameters
React with ❌ to remove this embed.
Angius
Angius10mo ago
EmbedDiscord.DiscordSenderOrWhatever.SendDiscordWebhook(true, "Unga Bunga Embed Title", string.Format("**{0}** Was Killed By **{1}** And Now Has **{2}** Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
EmbedDiscord.DiscordSenderOrWhatever.SendDiscordWebhook(true, "Unga Bunga Embed Title", string.Format("**{0}** Was Killed By **{1}** And Now Has **{2}** Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
TakingYourGF
TakingYourGFOP10mo ago
EmbedDiscord.DiscordSenderOrWhatever.SendDiscordWebhook(true, "KillFeed" string.Format("{0} Was Killed By {1} And Now Has {2} Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0])));
Angius
Angius10mo ago
Sure
TakingYourGF
TakingYourGFOP10mo ago
trying now yeah nothing
Angius
Angius10mo ago
I wonder if it's because Newtonsoft serializes the data with uppercase property names and Discord expects lowercase...
Angius
Angius10mo ago
Take your data classes
No description
Angius
Angius10mo ago
And add [JsonProperty("name")] attributes to the properties, where name is the property name but lowercase So
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
for example
TakingYourGF
TakingYourGFOP10mo ago
let me try that
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
so like this
TakingYourGF
TakingYourGFOP10mo ago
No description
Angius
Angius10mo ago
Yeah, normally you would await it, but it has some further-reaching implications So use the .GetAwaiter().GetResult() hack I mentioned before
TakingYourGF
TakingYourGFOP10mo ago
how would i add that tho? to the thing
Angius
Angius10mo ago
EmbedDiscord.DiscordSenderOrWhatever.SendDiscordWebhook(true, "Unga Bunga Embed Title", string.Format("**{0}** Was Killed By **{1}** And Now Has **{2}** Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0]))).GetAwaiter().GetResult();
EmbedDiscord.DiscordSenderOrWhatever.SendDiscordWebhook(true, "Unga Bunga Embed Title", string.Format("**{0}** Was Killed By **{1}** And Now Has **{2}** Death(s)!", kill_info[0], ReplaceDeathText(kill_info[1], replacements), new PlayerDatabase().GetDeathsByDisplayName(kill_info[0]))).GetAwaiter().GetResult();
TakingYourGF
TakingYourGFOP10mo ago
nothing still
Angius
Angius10mo ago
At this point I'd just use some Discord library, then
TakingYourGF
TakingYourGFOP10mo ago
lolol
Angius
Angius10mo ago
I... might actually whip up a Discord webhook library
TakingYourGF
TakingYourGFOP10mo ago
this is probably one of the most confusing shit i done lolol
Angius
Angius10mo ago
Once you understand what an API call is, what JSON is, and the basics of C#, it's not that hard But, yeah, you have to first learn those things Instead of jumping into deep water head-first
TakingYourGF
TakingYourGFOP10mo ago
Literally just need these messssges to be sent as a embed not a basic plain message lmao yeah fuck this shit lol @ZZZZZZZZZZZZZZZZZZZZZZZZZ last qustion where can i find the stuff about embed messages like title,name,message,tumbnail and etc figured it all out btw had to re code the messages bs lol
Angius
Angius10mo ago
On the Discord docs that I linked somewhere at the start
TakingYourGF
TakingYourGFOP10mo ago
type = "rich",
color = 0xcd402a,
title = ititle,
message = imessage,
thumbnail = new { url = "https://imgur.com/b6lGyF8.png" },
footer = new { text = DateTime.Now + " - Admin Pannel - " },
type = "rich",
color = 0xcd402a,
title = ititle,
message = imessage,
thumbnail = new { url = "https://imgur.com/b6lGyF8.png" },
footer = new { text = DateTime.Now + " - Admin Pannel - " },
like what else can i add to this?
Angius
Angius10mo ago
Anything mentioned in the docs
TakingYourGF
TakingYourGFOP10mo ago
okay one last thing
SendEmbedToWebhookEvents(Settings.EventWebhookUrl, "New Event", "**Chinook** Is Dropping A Crate", "").GetAwaiter().GetResult();
SendEmbedToWebhookEvents(Settings.EventWebhookUrl, "New Event", "**Chinook** Is Dropping A Crate", "").GetAwaiter().GetResult();
how would i add the image link into this
TakingYourGF
TakingYourGFOP10mo ago
No description
TakingYourGF
TakingYourGFOP10mo ago
so it looks like this
Angius
Angius10mo ago
The same way you're passing the URL, the title, and so on Add a parameter, put that parameter in the webhook object, serialize, send
TakingYourGF
TakingYourGFOP10mo ago
cs SendEmbedToWebhookEvents(Settings.EventWebhookUrl, "New Event", "**Chinook** Is Dropping A Crate", "", "https://i.imgur.com/CVGbaQu.png").GetAwaiter().GetResult();
cs SendEmbedToWebhookEvents(Settings.EventWebhookUrl, "New Event", "**Chinook** Is Dropping A Crate", "", "https://i.imgur.com/CVGbaQu.png").GetAwaiter().GetResult();
so like this? no lol
Angius
Angius10mo ago
For example, yeah You will need to add the new parameter to your method first, though Again, C# 101
TakingYourGF
TakingYourGFOP10mo ago
hmm wym?
Angius
Angius10mo ago
What I said If you have a method
public void Foo(int a, string b){}
public void Foo(int a, string b){}
you can call it with two parameters
Foo(69, "nice");
Foo(69, "nice");
You can't call it with Foo(69, "nice", true, false, new Person(), new int[]{1, 2, 3})
TakingYourGF
TakingYourGFOP10mo ago
static async Task SendEmbedToWebhookEvents(string webhookUrl, string ititle, string idescription, string iimage, string content)
{
using (HttpClient httpClient = new HttpClient())
{
var payload = new
{
content = content,
embeds = new[]
{
new
{
type = "rich",
color = 0xcd402a,
title = ititle,
description = idescription,
image = iimage,
thumbnail = new { url = "https://imgur.com/b6lGyF8.png" },
footer = new { text = DateTime.Now + " - Admin Pannel - " },

}
}
};

string jsonPayload = Newtonsoft.Json.JsonConvert.SerializeObject(payload);

using (var contentData = new StringContent(jsonPayload, Encoding.UTF8, "application/json"))
{
await httpClient.PostAsync(webhookUrl, contentData);
}
}
}
static async Task SendEmbedToWebhookEvents(string webhookUrl, string ititle, string idescription, string iimage, string content)
{
using (HttpClient httpClient = new HttpClient())
{
var payload = new
{
content = content,
embeds = new[]
{
new
{
type = "rich",
color = 0xcd402a,
title = ititle,
description = idescription,
image = iimage,
thumbnail = new { url = "https://imgur.com/b6lGyF8.png" },
footer = new { text = DateTime.Now + " - Admin Pannel - " },

}
}
};

string jsonPayload = Newtonsoft.Json.JsonConvert.SerializeObject(payload);

using (var contentData = new StringContent(jsonPayload, Encoding.UTF8, "application/json"))
{
await httpClient.PostAsync(webhookUrl, contentData);
}
}
}
this is what i have right now
Angius
Angius10mo ago
I see the iimage parameter That is, presumably, the image link?
TakingYourGF
TakingYourGFOP10mo ago
yeah should be if not its the one before that
Angius
Angius10mo ago
Then, yeah, it looks fine
TakingYourGF
TakingYourGFOP10mo ago
SendEmbedToWebhookEvents(Settings.EventWebhookUrl, "New Event", "**Chinook** Is Dropping A Crate", "", "https://i.imgur.com/CVGbaQu.png").GetAwaiter().GetResult();
SendEmbedToWebhookEvents(Settings.EventWebhookUrl, "New Event", "**Chinook** Is Dropping A Crate", "", "https://i.imgur.com/CVGbaQu.png").GetAwaiter().GetResult();
thats how i got it
Angius
Angius10mo ago
Look at your parameters
string webhookUrl, string ititle, string idescription, string iimage, string content
string webhookUrl, string ititle, string idescription, string iimage, string content
string webhookUrl Settings.EventWebhookUrl
string ititle "New Event"
string idescription "**Chinook** Is Dropping A Crate"
string iimage ""
string content "https://i.imgur.com/CVGbaQu.png"
string webhookUrl Settings.EventWebhookUrl
string ititle "New Event"
string idescription "**Chinook** Is Dropping A Crate"
string iimage ""
string content "https://i.imgur.com/CVGbaQu.png"
Here's what you're passing to your method
TakingYourGF
TakingYourGFOP10mo ago
ooo nope that broke for some reason hmm
SendEmbedToWebhookEvents(Settings.EventWebhookUrl, "New Event", "An **Air Drop** Is Inbound!", "https://i.imgur.com/CVGbaQu.png").GetAwaiter().GetResult();
SendEmbedToWebhookEvents(Settings.EventWebhookUrl, "New Event", "An **Air Drop** Is Inbound!", "https://i.imgur.com/CVGbaQu.png").GetAwaiter().GetResult();
almost got it all done yeah image broke it hmm
Angius
Angius10mo ago
No description
Angius
Angius10mo ago
Notice how image is an object not just a string
Angius
Angius10mo ago
Click the blue link and you see
No description
TakingYourGF
TakingYourGFOP10mo ago
what does that mean tho lol
Angius
Angius10mo ago
That the image property of the embed is not a simple string It's a complex object It's not
{
...,
"image": "https://images.com/image.png"
}
{
...,
"image": "https://images.com/image.png"
}
but rather
{
...,
"image": {
"url": "https://images.com/image.png",
"width": // optional
// etc
}
}
{
...,
"image": {
"url": "https://images.com/image.png",
"width": // optional
// etc
}
}
TakingYourGF
TakingYourGFOP10mo ago
hmm
Want results from more Discord servers?
Add your server