#difficulties translating between requiring modules and importing them

8 messages · Page 1 of 1 (latest)

vagrant vector

The code has discord.js content but the issue is not discord.js related

ionic needleBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
vagrant vector
import dotenv from "dotenv"
dotenv.config()
import { REST, Routes } from "discord.js"

const commands = [
    {
        name: "hey",
        description: "Replies with hey",
    }
]


const rest = new REST({ version: "10" }).setToken(process.env.TOKEN)

(async () => {

    try {

        console.log("Registered slash commands.")

        await rest.put(
            Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID),
            {
                body: commands
            }
        )

        console.log("Registering slash commands.")
    } catch (error) {
        console.log(`there was an error: ${error}`)
    }

})()

error:

TypeError: (intermediate value).setToken(...) is not a function
    at file:///C:/Users/yusuf/OneDrive/Documents/Programming%20Projects/Discord%20bots/slashBot/src/register-commands.js:15:1
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

if someone can link some sort of tutorial to help me translate between importing modules and requiring them then that would be very helpful as I am new to discord.js and do not understand this concept

tidal sleet

add a ; after setToken

vagrant vector

oh