Deploy Commands
Hi, I'm a new user on discord.js, I would like to know if I can make it so that when the bot joins a server it creates commands in that server (I use slash commands and module.exports) as far as I know this function works calls deploy-commands, but I can't find anything on the internet. Can you help me?
18 Replies
• 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.discord.js : [email protected]
node : v16.17.0
You just have to deploy the commands globally
How do you do ?
Excuse my ignorance but I'm new and know almost nothing
There is a code example
or show your code where you deploy the commands please
C:\Users\MATTEO\Desktop\PizzaBot\index.js:20
await rest.put(
^^^^^
SyntaxError: await is only valid in async functions and the top level bodies of modules
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1055:15)
at Module._compile (node:internal/modules/cjs/loader:1090:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
this is my index.js
and this is the error
hmm
please read your error
You’re using await in a non asynchronous function
Remove the
await
ok
C:\Users\MATTEO\Desktop\PizzaBot\index.js:20
rest.put(
^
ReferenceError: rest is not defined
at Object.<anonymous> (C:\Users\MATTEO\Desktop\PizzaBot\index.js:20:9)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
now i have this error
it says rest is not defined, what library should i use to define it?
@endergamermc
You need to define the REST
const rest = new REST({ version: '10' }).setToken(token);
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
There is a code example
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
so I should make another file named deploy.js and put the global commands code there?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View