How to make fields with multi tables? (Discord Webhook)

  1. What do you want to achieve? i want to print the fields(Discord Webhook) that it have multi tables

  2. What is the issue? I dont know how to make discord fields with tables

  3. What solutions have you tried so far? I had looked every devhub about discord webhook.

In my option, i want to make Join Log but have function like Application that can skip the answer, (if it has many Question) it must to have tables right?
If player skip the answer, it will not show on Fields
If player didn’t skip answer, it will show normally

		local function Embed_Fields(name:string, value:string, inline:boolean)
			local Fields = {name, value, inline}
			return Fields
		end
		
		local Embed_Device = nil
		local Embed_RunService = nil
		local Final_Embed = nil
		local Final_Fields = {}
		Embed_Device = Embed_Fields("Device", Device__(), true)
		Embed_RunService = Embed_Fields("RunService", RunService__(), true)
		Final_Embed = {Embed_Device and Embed_RunService}
		for i, v in pairs(Final_Embed) do
			print(i, v)
			table.insert(Final_Fields, {
				["name"] = tostring(v[1]),
				["value"] = tostring(v[2]),
				["inline"] = tostring(v[2])
			})
		end
		local function Final()
			for i, v in pairs(Final_Fields) do
				print(i, v)
				task.wait(#Final_Fields)
				return Final_Fields[i]
			end
		end	
		print(Final())

local joindata = {
   -- embeds
}

Http:PostAsync(webhook,Http:JSONEncode(joindata))

Hi!

While reading your code, i have noticed some error with it,
On the line 18, I think you meant to put ["inline"] = v[3]

Since discord’s field object is the following

type Field = {
   name: string,
   value: string,
   inline: boolean?
}

To use fields with a multiple table, you can just pass it to the embed’ fields.

For example

local fields = {
   {name = "Hello", value = "World", inline = true},
   {name = "This",  value = "is an example", inline = true}
}

local postData = {
   embeds = {
      {
         fields = fields
      }
   }
}

Http:PostAsync(webhook,Http:JSONEncode(postData))

Reference:

Hopes this help!

I’m sure that my discord’s field object is correct.
But when I print (i, v) to check the table, it shows only one.
What do I have to do?

My last Update with Output:

Oh!

The inline value have to be a boolean not string, so you should remove the tostring() and pass v[3] directly!
and on the Final_Embed line, you use , to separate a table’s value, not and.

local tableofstuff = {a, b}
2 Likes

magic, it work but now. it happened below that line. (Follow the image)

Result :
image

The reason why Final() only return 1 value is because in the loop,
You have return Final_Fields[i], which will always return the first element of Final_Fields,
( in case you don’t know, return end the loop )
I don’t know the purpose of the Final() but it’s better to just not use that function, you can just pass Final_Fields in directly without the use of Final().

1 Like

when i use Final_Fields then it output HTTP 400 (Bad Request), maybe because the Final_Fields need to be Final_Fields[1], Final_Fields[2] right?

also Final_Embed too

Ah,

You have to unpack the Final_Fields by using table.unpack,
Right now it’s being treated as
fields = { {Field}, { {Field}, {Field} } }
So, When you use table.unpack(Final_Fields), it will be treated as
fields = { {Field}, {Field}, {Field} }
Example
fields = { {Field}, table.unpack(Final_Fields)}

i changed from Final_Fields to Pre_Final_Fields
and add new the variable as Final_Fields

When i unpack, it add new table as void [1] = {}

Ah, no.

you were suppose to do

{
   fields = {
    {
     name = "Account Daycount(s)",
     value = plr.AccountAge,
     inline = true
    },
    table.unpack(Final_Fields)
   }
}

No need for Pre_final_Fields and stuff.

damn, i’m so sorry. im beginner.
For now, it shows only one field. Where is the other one?

In Console (after table.unpack) :
image

This is weird,

It should work, Have you commit it?
Because if it doesn’t work, it should error out.

If you already commit it,
Please send me the part where you insert field into Final_Fields

here you are.

Very weird behavior,

Try printing the joindata.

I’m busy and probably won’t get back to you in a week, so here’s another question for you.
How do I get it to bypass the result if I set it not to show? (If i setting like “ShowDevice = false”)

Seem like Adonis Setting function but change from in game to on Discord Webhook :slight_smile:
thanks in advance.

I am not sure on why the table.unpack method failed,

But i am sure that for something like Adonis Setting function
You can probably do

local Final_Embed = {}

if Settings.Device then
      table.insert(Final_Embed, Embed_Fields("Device", Device__(), true))
end
2 Likes

Ok, im come back.
it work well but i have problam with table.unpack again.


image