Please describe the problem you are having in as much detail as possible:
I just started using Webhooks a couple of minutes ago, and I ran into an issue. Here's my code:
const config = require("../config.json");
const Discord = require("discord.js");
const hooker = new Discord.WebhookClient(config.webhook.id, config.webhook.token);
module.exports = hooker.send;
The webhook ID and token are not undefined or anything, but when I try to run this:
require("./log.js")("Test")
I get this error:
TypeError: Cannot read property 'client' of undefined
at send (F:\Projects\Guess That Number\node_modules\discord.js\src\structures\Webhook.js:125:16)
at eval (eval at execute (F:\Projects\Guess That Number\commands\eval.js:19:40), <anonymous>:2:1)
at Object.execute (F:\Projects\Guess That Number\commands\eval.js:19:40)
at module.exports (F:\Projects\Guess That Number\functions\handle-message.js:25:38)
at Client.bot.on (F:\Projects\Guess That Number\events\message.js:4:32)
at emitOne (events.js:96:13)
at Client.emit (events.js:191:7)
at MessageCreateHandler.handle (F:\Projects\Guess That Number\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (F:\Projects\Guess That Number\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:102:65)
at WebSocketConnection.onPacket (F:\Projects\Guess That Number\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:325:35)
at WebSocketConnection.onMessage (F:\Projects\Guess That Number\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:288:17)
I just tested this on discord.js v12, and I get this error:
TypeError: Cannot read property 'name' of undefined
at send (F:\Projects\Guess That Number\node_modules\discord.js\src\structures\Webhook.js:111:51)
at eval (eval at execute (F:\Projects\Guess That Number\commands\eval.js:19:40), <anonymous>:2:1)
at Object.execute (F:\Projects\Guess That Number\commands\eval.js:19:40)
at module.exports (F:\Projects\Guess That Number\functions\handle-message.js:25:38)
at Client.bot.on (F:\Projects\Guess That Number\events\message.js:4:32)
at emitOne (events.js:96:13)
at Client.emit (events.js:191:7)
at MessageCreateHandler.handle (F:\Projects\Guess That Number\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (F:\Projects\Guess That Number\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (F:\Projects\Guess That Number\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:332:35)
at WebSocketConnection.onMessage (F:\Projects\Guess That Number\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:294:22)
I don't exactly know what the error is, but can anyone help? It doesn't look like it's an error with my code, because the main stracktrace goes back to the lib itself. Can anyone help?
Include a reproducible code sample here, if possible:
const config = require("../config.json");
const Discord = require("discord.js");
const hooker = new Discord.WebhookClient(config.webhook.id, config.webhook.token);
module.exports = hooker.send;
Further details:
thats not a lib issue, this for lib issues
You have to bind the context.
module.exports = hooker.send.bind(hooker);
@SpaceEEC Thanks, that worked!
Most helpful comment
You have to bind the context.
module.exports = hooker.send.bind(hooker);