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/[email protected] NodeJS: v18.12.0
26 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
sean
seanOP2y ago
v18
vladdy
vladdy2y ago
you can see the node version already Qjuh
sean
seanOP2y ago
[email protected] installed here also the latest version now error still there
vladdy
vladdy2y 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
seanOP2y ago
sure
sean
seanOP2y ago
Updated it now and deleted what u requested before reinstalling Error still happen :(
vladdy
vladdy2y ago
Thonk I've recently made a bot with djs rest and it worked fine that said I AM on 18.14.0
sean
seanOP2y 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
vladdy2y 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
seanOP2y 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
vladdy2y ago
Can you share your rest instance options?
sean
seanOP2y 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
vladdy2y 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
seanOP2y ago
does setAgent not set "User-Agent" ?
vladdy
vladdy2y ago
nop, and types should've told you that
sean
seanOP2y ago
sean
seanOP2y ago
i though its the useragent lol
vladdy
vladdy2y ago
i mean agent: BLELELE you used TS it would've yelled at you)
sean
seanOP2y ago
Yeah but I dont use ts x D
vladdy
vladdy2y ago
fair nuff
sean
seanOP2y ago
I'm to lazy for this typing stuff xD I try it now
vladdy
vladdy2y ago
Also we don't allow overwriting the user-agent fully, but we do let you append extra data to it
sean
seanOP2y ago
Also fine Okay it works now thank you for your help !
vladdy
vladdy2y ago
no worries
Want results from more Discord servers?
Add your server