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
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)String interpolation is the preferred way of building strings in C#. It is easier to read than concatenation.
For example:
can be written as:
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
$code
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/i have it sending like this i wanna make this message from what i got into a embed message
Angius
Idk, what Discord library are you using?
Quoted by
<@85903769203642368> from #how to make this into a embed message with webhook (click here)
React with ❌ to remove this embed.
If none, what's
SendDiscordWebhook
?trying to make it look like this
I KNOW what embeds are
Answer my questions
aint using a discord library
I see, yes
Give me a moment
thanks brother
im new to the whole discord shit lolol
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
yeah i was looking at these already
Now we know we need to send JSON data that looks like
Easiest way, is to make classes (or records) that represent this structure, create those objects, serialize it to JSON, and send that
(notice my use of
HttpClient
, since WebClient
is long since deprecated)yeah i dont understand how i would make what i have into a embed lol
Or, well, any other data you want to include
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
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
would rather just have someone covert it for me
to embed and etc
lool
cuz this shit got me lost asf
Sure, if you'd rather pay
yeah i will pay idc
lolol
I prefer learning, but to each their own
yeah im lost asf tho
how to chnge it all to make it okr
work
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 changeSorry @TakingYourGF your message contained blocked content and has been removed!
Sorry @TakingYourGF your message contained blocked content and has been removed!
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
Changing your
SendDiscordWebhook
message to this
so i would full on change this?
to what you sent me
Or, let's make it more understandable maybe
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 headersso i want something like this
Yes, that would describe your message structure
do i need a library ?
to add
To add what?
cuz i see alot of the red lnes
Yeah, idk why
Where did you place the code?
And what do the errors say?
under my form1
with all my other classes
Ah, huh, I would guess you're using an outdated version of .NET?
Remove the
required
then and turn init
into set
okay now what
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
And the errors this time are?
Ah, whoops
And, yeah, you supply the URL
Your webhook URL to be precise
okay so wait i have it so you put the webhook inside another file
a config file
Yeah, it would be best to not hardcode it
i have it in a config file
Cool
config.json
Read it from the config and pass it as the url
var response = client.UploadValues(killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl, "POST", data);
this is what i got atm
Looks like
killfeed ? Settings.KillFeedWebhookUrl : Settings.EventWebhookUrl
would decide your webhook URL then
so it should look like this
Yeah
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 thatSorry,
System.Net.Http.Json
wrong lolol
Json
not json
either works lol
Ah, yeah, guess it's not there
In that case,
needs to become
Assuming... your version of .NET has
System.Text.Json
namespaceWhat's the error on
Serialize
?I guess that's Newtonsoft...? That's why I diteched old versions long ago lmao
Try
SerializeObject
?
Instead of Serialize
nope
JsonConvert.SerializeObject(data)
...?that worked lol
Looks right ?
I think so, yeah
okay so this is done now what?
Now use this method to send an embed
how would i make this work?
What doesn't work about it?
wait confused
should i try it lol?
should i delete this one now?
or what?
Keep it
ok
I don't suppose you have version control set up, so keep it just in case
so how would i make the stuff use the embed now?
You would call the new method instead of the old one
I guess make it static
like what would i replace?
so ik
And use
Instead of your current method
Ah, I don't suppose the calling method is asynchronous... you mentioned it's winforms, right?
Fuck it then,
Sorry, I'm unwilling to delve into explaining what asynchronous code is and how to make it work with Winforms now lol
would i just do this?
For example, yes
Ideally after solving the errors, whatever they are
this is where it sends it
so how would i make it use the embed instea
What do you mean
Like this
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
Ah, make sure the class is
public
And, ideally, have it in a separate file
Nor as a nested class of the Form1
classshould i just make a full new class
for the discordSenderOrwhatever
The convention is that every class has its own file, yes
fuck me
See how you had it done in your original method
You had
Settings = new Settings()
right?yeah
its not even locked lol
fixed one error goes into antoher one
Make the method
public
it is lolol
What's the full error?
Can you try quick fixes?
trying it now
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
yeah that didnt work lol
Give it
true, "whatever title", string.Format(......
as the parameterswait wym
im confused
this is what i got right now
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 threeso what should i do lol
confused asf
Angius
Give it
true, "whatever title", string.Format(......
as the parametersQuoted by
<@85903769203642368> from #how to make this into a embed message with webhook (click here)
React with ❌ to remove this embed.
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])));
Sure
trying now
yeah nothing
I wonder if it's because Newtonsoft serializes the data with uppercase property names and Discord expects lowercase...
Take your data classes
And add
[JsonProperty("name")]
attributes to the properties, where name
is the property name but lowercase
So
for examplelet me try that
so like this
Yeah, normally you would await it, but it has some further-reaching implications
So use the
.GetAwaiter().GetResult()
hack I mentioned beforehow would i add that tho?
to the thing
nothing still
At this point I'd just use some Discord library, then
lolol
I... might actually whip up a Discord webhook library
this is probably one of the most confusing shit i done
lolol
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
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
On the Discord docs that I linked somewhere at the start
like what else can i add to this?
Anything mentioned in the docs
okay one last thing
how would i add the image link into this
so it looks like this
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
so like this?
no lol
For example, yeah
You will need to add the new parameter to your method first, though
Again, C# 101
hmm
wym?
What I said
If you have a method
you can call it with two parameters
You can't call it with
Foo(69, "nice", true, false, new Person(), new int[]{1, 2, 3})
this is what i have
right now
I see the
iimage
parameter
That is, presumably, the image link?yeah should be if not its the one before that
Then, yeah, it looks fine
thats how i got it
Look at your parameters
Here's what you're passing to your method
ooo
nope that broke for some reason hmm
almost got it all done
yeah image broke it hmm
Notice how image is an object not just a string
Click the blue link and you see
what does that mean tho lol
That the
image
property of the embed is not a simple string
It's a complex object
It's not
but rather
hmm