#TypeError: Cannot destructure property 'id' of 'data' as it is undefined.

54 messages · Page 1 of 1 (latest)

blazing saffron
#

trying to use a webhook

#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

#
import { EmbedBuilder, WebhookClient } from "discord.js";

const wh = new WebhookClient(process.env.WEBHOOK_URL);

export async function logger(req, res, nextz) {
    var incomingIP = req.ip.split(':').pop();
    const logEmbed = new EmbedBuilder()
    .setColor(0xfa9a50)
    .setTitle(`Request Recieved.`)
    .addFields(
        { name: "Request type:", value: `\`\`\`${req.method}\`\`\``, inline: true },
        { name: "Request endpoint", value: `\`\`\`${req.baseUrl}\`\`\``, inline: true },
        { name: "Request IP Adress", value: `\`\`\`${incomingIP}\`\`\``, inline: true }
    )
    wh.send(logEmbed)
    next()
} 


#
❯ node -v
v18.12.1
gusty matrix
#

okay

#

whats the problem with it

blazing saffron
#

the thread name @gusty matrix

gusty matrix
#

show your error

#

full stack

blazing saffron
#
    let { id, token } = data;
          ^

TypeError: Cannot destructure property 'id' of 'data' as it is undefined.
    at new WebhookClient (C:\Users\corrupted\Desktop\Projects\Landify\node_modules\discord.js\src\cli
ent\WebhookClient.js:46:11)
    at file:///C:/Users/corrupted/Desktop/Projects/Landify/utils/logging.js:3:12
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)
gusty matrix
#

try using id and token

blazing saffron
#

why would i use that im trying to use wbhooks

gusty matrix
#

yeah,

#

use webhookid and token

blazing saffron
#

how do i get those

gusty matrix
#

go to the webhook url

#

the object contains id and token

blazing saffron
#

oh t hank

gusty matrix
#

const wh = new WebhookClient({ token: process.env.WEBHOOK_URL });

#

try that

blazing saffron
#

fixed

#

that

gusty matrix
#

works?

blazing saffron
#

let me

gusty matrix
#

i think webhooks take an object, not sure tho

blazing saffron
#

uh oh

gusty matrix
#

uh oh what

blazing saffron
#

look

#
        { name: "Request endpoint", value: `\`\`\`${req.baseUrl}\`\`\``, inline: true },
gusty matrix
#

yeah?

blazing saffron
#

why is it

gusty matrix
#

req.baseUrl is undefined

#

log it rq

blazing saffron
#

no it isnr

#

i logged it

#

it returns /api

gusty matrix
#

weird

#

try again

blazing saffron
gusty matrix
blazing saffron
gusty matrix
#

you need to stringify it

blazing saffron
#

why is it not just showing the object like

{}
gusty matrix
#

log it

blazing saffron
#

it logs object Object

gusty matrix
#

ok

#

so

blazing saffron
#
    .setDescription(`\`\`\`${req.body}\`\`\``)
blazing saffron
gusty matrix
#

i cant really think of an answer

summer narwhal