TypeError: this.dispatch is not a function

Hi Guys I use @discordjs/rest but when I try to do a request I always get:
TypeError: this.dispatch is not a function
at String.request (/root/testApp/node_modules/undici/lib/api/api-request.js:193:10)
at /root/testApp/node_modules/undici/lib/api/api-request.js:186:15
at new Promise (<anonymous>)
at String.request (/root/testApp/node_modules/undici/lib/api/api-request.js:185:12)
at /root/testApp/node_modules/undici/index.js:83:15
at SequentialHandler.runRequest (/root/testApp/node_modules/@discordjs/rest/dist/index.js:531:46)
at SequentialHandler.queueRequest (/root/testApp/node_modules/@discordjs/rest/dist/index.js:464:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
TypeError: this.dispatch is not a function
at String.request (/root/testApp/node_modules/undici/lib/api/api-request.js:193:10)
at /root/testApp/node_modules/undici/lib/api/api-request.js:186:15
at new Promise (<anonymous>)
at String.request (/root/testApp/node_modules/undici/lib/api/api-request.js:185:12)
at /root/testApp/node_modules/undici/index.js:83:15
at SequentialHandler.runRequest (/root/testApp/node_modules/@discordjs/rest/dist/index.js:531:46)
at SequentialHandler.queueRequest (/root/testApp/node_modules/@discordjs/rest/dist/index.js:464:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
My Code:
rest
.get(Routes.user(this.applicationId))
.then(data => {
this.emit('debug', "[DEBUG] Got the client data from the API");
this.user = new User(data);
}).catch(e => {
this.emit('debug', "[DEBUG] Got a error by fetching the client data from the API!" + e);
console.log(e)
});
rest
.get(Routes.user(this.applicationId))
.then(data => {
this.emit('debug', "[DEBUG] Got the client data from the API");
this.user = new User(data);
}).catch(e => {
this.emit('debug', "[DEBUG] Got a error by fetching the client data from the API!" + e);
console.log(e)
});
NPM Version: @discordjs/rest@1.5.0 NodeJS: v18.12.0
26 Replies
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
sean
sean15mo ago
v18
vladdy
vladdy15mo ago
you can see the node version already Qjuh
sean
sean15mo ago
undici@5.13.0 installed here also the latest version now error still there
vladdy
vladdy15mo ago
interesting, thats quite an old undici version can you nuke your lockfile and node_modules folder and reinstall deps? and then ls again
sean
sean15mo ago
sure
sean
sean15mo ago
Updated it now and deleted what u requested before reinstalling Error still happen :(
vladdy
vladdy15mo ago
Thonk I've recently made a bot with djs rest and it worked fine that said I AM on 18.14.0
sean
sean15mo ago
Same, but now I have this and idk why xD I could try updating my nodejs on my server in hope that it dont break my other bots OMEGALUL
vladdy
vladdy15mo ago
it definitely shouldn't break ..can you get a fresh stack trace because that stack doesn't match with undici code The agent breaking tho
sean
sean15mo ago
no
TypeError: this.dispatch is not a function
at String.request (/root/testApp/node_modules/undici/lib/api/api-request.js:193:10)
at /root/testApp/node_modules/undici/lib/api/api-request.js:186:15
at new Promise (<anonymous>)
at String.request (/root/testApp/node_modules/undici/lib/api/api-request.js:185:12)
at /root/testApp/node_modules/undici/index.js:87:15
at SequentialHandler.runRequest (/root/testApp/node_modules/@discordjs/rest/dist/index.js:531:46)
at SequentialHandler.queueRequest (/root/testApp/node_modules/@discordjs/rest/dist/index.js:464:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
TypeError: this.dispatch is not a function
at String.request (/root/testApp/node_modules/undici/lib/api/api-request.js:193:10)
at /root/testApp/node_modules/undici/lib/api/api-request.js:186:15
at new Promise (<anonymous>)
at String.request (/root/testApp/node_modules/undici/lib/api/api-request.js:185:12)
at /root/testApp/node_modules/undici/index.js:87:15
at SequentialHandler.runRequest (/root/testApp/node_modules/@discordjs/rest/dist/index.js:531:46)
at SequentialHandler.queueRequest (/root/testApp/node_modules/@discordjs/rest/dist/index.js:464:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
thats the trace now
vladdy
vladdy15mo ago
Can you share your rest instance options?
sean
sean15mo ago
1. sec im eating something now
const {REST} = require('@discordjs/rest');

Rest.rest = new REST({version: '10'})
.setAgent('Discord Interactions.js Package (https://github.com/fb-sean/interactions.js)')
.setToken(process.env.DISCORD_TOKEN);

return Rest.rest;
const {REST} = require('@discordjs/rest');

Rest.rest = new REST({version: '10'})
.setAgent('Discord Interactions.js Package (https://github.com/fb-sean/interactions.js)')
.setToken(process.env.DISCORD_TOKEN);

return Rest.rest;
vladdy
vladdy15mo ago
... YEAH ok so thats not what you use setAgent for you're looking for userAgentAppendix option in the constructor sooo remove the setAgent line and it'll all work
sean
sean15mo ago
does setAgent not set "User-Agent" ?
vladdy
vladdy15mo ago
nop, and types should've told you that
sean
sean15mo ago
sean
sean15mo ago
i though its the useragent lol
vladdy
vladdy15mo ago
i mean agent: BLELELE you used TS it would've yelled at you)
sean
sean15mo ago
Yeah but I dont use ts x D
vladdy
vladdy15mo ago
fair nuff
sean
sean15mo ago
I'm to lazy for this typing stuff xD I try it now
vladdy
vladdy15mo ago
Also we don't allow overwriting the user-agent fully, but we do let you append extra data to it
sean
sean15mo ago
Also fine Okay it works now thank you for your help !
vladdy
vladdy15mo ago
no worries