ReferenceError: interaction is not defined

DiscordAPIError: Invalid Form Body error when i load my slash commands into my discord bot
34 Replies
d.js toolkit
d.js toolkit2y ago
• 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.
ghehusbcbrhjrjxnnxnnxnx
node -v : v16.16.0 discord.js: [email protected]
Danial
Danial2y ago
Show full error
ghehusbcbrhjrjxnnxnnxnx
alright here so whenever i do a slash command it give this error
ghehusbcbrhjrjxnnxnnxnx
and in my terminal it says @Danial
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ghehusbcbrhjrjxnnxnnxnx
the terminal says this
ghehusbcbrhjrjxnnxnnxnx
whenever i do a slash command with my bot
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ghehusbcbrhjrjxnnxnnxnx
it says ReferenceError: interaction is not defined
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ghehusbcbrhjrjxnnxnnxnx
wdym you want the code?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ghehusbcbrhjrjxnnxnnxnx
alright
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ghehusbcbrhjrjxnnxnnxnx
here is the code
module.exports = {
name: "interactionCreate",
run: async (bot, interaction) => {
if (interaction.isCommand()) handleSlashCommand(bot, interaction)
else if (interaction.isButton()) handleButton(bot, interaction)
},
}

const handleButton = (bot, interaction) => {
const {client} = bot

// "name-param1-param2-...."
const [name, ...params] = interaction.customId.split("-")

const button = client.buttons.get(name)

if (!button) return
button.run(client, interaction, params)
}

const handleSlashCommand = (bot, interaction) => {
const {client} = bot
console.log('1')
if (!interaction.inGuild()) return interaction.reply("This command can only be used in a guild")

const slashcmd = client.slashcommands.get(interaction.commandName)

if (!slashcmd) return

// check permissions
if (slashcmd.perms && !interaction.member.permissions.has(slashcmd.perms))
return interaction.reply("You do not have permission to use this command")

slashcmd.run(client, interaction)
}
module.exports = {
name: "interactionCreate",
run: async (bot, interaction) => {
if (interaction.isCommand()) handleSlashCommand(bot, interaction)
else if (interaction.isButton()) handleButton(bot, interaction)
},
}

const handleButton = (bot, interaction) => {
const {client} = bot

// "name-param1-param2-...."
const [name, ...params] = interaction.customId.split("-")

const button = client.buttons.get(name)

if (!button) return
button.run(client, interaction, params)
}

const handleSlashCommand = (bot, interaction) => {
const {client} = bot
console.log('1')
if (!interaction.inGuild()) return interaction.reply("This command can only be used in a guild")

const slashcmd = client.slashcommands.get(interaction.commandName)

if (!slashcmd) return

// check permissions
if (slashcmd.perms && !interaction.member.permissions.has(slashcmd.perms))
return interaction.reply("You do not have permission to use this command")

slashcmd.run(client, interaction)
}
@Danial
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ghehusbcbrhjrjxnnxnnxnx
bro i did
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ghehusbcbrhjrjxnnxnnxnx
alr
if(!interaction.iscommand()) return
^

ReferenceError: interaction is not defined
if(!interaction.iscommand()) return
^

ReferenceError: interaction is not defined
trplnr
trplnr2y ago
it says the error directly to u interaction is not defined
royc
royc2y ago
where is handleButton getting called from
ghehusbcbrhjrjxnnxnnxnx
interactioncreate
royc
royc2y ago
and run?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
royc
royc2y ago
something is not right, if interaction is undefined yeah either stack trace or more code idk easiest way to get it right is debug interaction
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
GuiguiBlocCraft
This code part isn't in your module code You can check in your index.js, with line num in the error
ghehusbcbrhjrjxnnxnnxnx
that is the error do you want me to show you my index.js? alr
Nightro-Fx
Nightro-Fx14mo ago
@Dinnerfork Ik this is kina late but... did it get solved in the end?
Want results from more Discord servers?
Add your server