#Expected token to be set for this request, but none was present

31 messages · Page 1 of 1 (latest)

hard knot
#

Im getting some error the discord token is valid

somber harbor
#

see #faq for tips on how to ask questions

hard knot
#
const discordToken = process.env[""];
const channelId = process.env["1089592410360782908"];
const guildId = process.env["1089572362460078120"];
const clientId = process.env["1085245543208464455"];
    const rest = new REST({ version: '10' }).setToken(discordToken);
    await rest.put(
        Routes.applicationGuildCommands(clientId, guildId),
        { body: [activateCommand.toJSON(), statusCommand.toJSON(), deactivateCommand.toJSON()] },
    );
}
somber harbor
#

what's with the weird ENV variables?

#

obviously discordToken will not be set

hard knot
#

why not

#

oh

somber harbor
#

because you gave it an empty property name

hard knot
#

i removed the token

somber harbor
#

that's not a token

hard knot
#

the blank thing in discordToken there should be normally a discord token i removed it

somber harbor
#

those numbers are environment variable names. those are not tokens/values.

hard knot
#

you want me to send the full code?

somber harbor
#

you can send whatever you want. I'm telling you that's your issue. you're not using process.env correctly

hard knot
hard knot
#

@somber harbor

somber harbor
#

why ping me? I already told you what you're doing wrong.

hard knot
#

why wrong?

#

whats wrong about it

somber harbor
#

that's not how process.env works

#

(as I explained)

#

if you want to assign a string to a variable, assign the string to a variable. don't randomly try to use an environment variable that isn't set.

somber harbor
#

what exactly would you like me to do? write your code for you? I've told you exactly what to fix and how it's wrong.

hard knot
#

i dont really understand what you mean

somber harbor
#

what do you think process.env does?

hard knot
#

safe in variables?

hard knot
# somber harbor <https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processenv>

if i understood this correctly i did now this

process.env

TOKEN=discordtoken
CHANNEL_ID=1089592410360782908
GUILD_ID=1089572362460078120
CLIENT_ID=1085245543208464455

**
index.js**

const discordToken = process.env["TOKEN"];
const channelId = process.env["CHANNEL_ID"];
const guildId = process.env["GUILD_ID"];
const clientId = process.env["CLIENT_ID"];
somber harbor
#

Almost right, but the file shouldn’t be named process.env.