Search code examples
javascriptdiscorddiscord.js

discord.js v13 message is not defined?


I was using v12 now I've to upgrade v13 anyhow. Now I was trying slash commands. but I got an error same command is working fine on my prefix but in slash it's not working.

client.on('messageCreate', message => {
    
    const guildId = "914573324485541928"
    const guild = client.guilds.cache.get(guildId)
    let commands

    if (guild) {
      commands = guild.commands
    } else {
      commands = client.application.commands
    }

    commands.create({
      name: 'ping',
      description: 'Replies with pong'
    })
    commands.create({
      name: 'truth',
      description: 'Replies with a random truth question'
    })
    commands.create({
      name: 'dare',
      description: 'Replies with a random dare question'
    })
    commands.create({
      name: 'truthbangla',
      description: 'Replies with a random bangla truth question'
    })
    commands.create({
      name: 'darebangla',
      description: 'Replies with a random bangla dare questions'
    })
    commands.create({
      name: 'invite',
      description: 'Get the invite link of this bot'
    })
    commands.create({
      name: 'help',
      description: 'Replies with all list of commands'
    })
    commands.create({
      name: 'vote',
      description: 'Get the vote url to vote our bot'
    })
    commands.create({
      name: 'info',
      description: 'Replies with all info of this bot'
    })

  });
  client.on('interactionCreate', async (interaction) => {
    if(!interaction.isCommand()){
      return
    }

    const { commandName, options } = interaction 

    if(commandName === 'help'){
      const user = interaction.options.getUser('target');
      const help = new MessageEmbed()
      .setColor('#111133')
      .setTitle("Truth Or Dare")
      .setURL('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')
      .addFields(
        { name: 'For Help', value: '```+help```' },
        { name: 'For Your Truth', value: '```+t```', inline: true },
        { name: 'For Your Dare', value: '```+d```', inline: true},
        { name: 'For Invite this bot on your server', value: '```+invite```' },
        { name: 'For Truth Questions Bangla', value:'```+tb```', inline: true},
        { name: 'For Dare Questions Bangla', value:'```+db```', inline: true},
        { name: 'For Vote Our Bot', value:'```+vote```'},
        { name: 'Created By', value: '<@723821826291138611> [**Leader at CODE HUNTER**]' },
      )
      .setDescription(
        `Truth Or Dare Bot Version: v${require("./package.json").version}
  [Website](https://web-truthordare.web.app/) | [Support Server](https://discord.gg/djhNPX2QUp) | By [Code Hunter](https://github.com/Code-Hunter-OfficialBD/)`
      )
      .setTimestamp()
      .setFooter(`${message.author.username} `, message.author.displayAvatarURL());
    interaction.reply({
      embeds: [help]
    })
    }
  })

and this is the error

.setFooter(`${message.author.username} `, message.author.displayAvatarURL());
                    ^

ReferenceError: message is not defined

now I don't know what's the matter but in my main prefix it works perfectly. in slash commands it's sucks. What do I've to do?


Solution

  • I believe you are trying to reference message instead of interaction. You are running that code in interactionCreate and named your parameter as interaction.

        const help = new MessageEmbed()
           // ...
          .setFooter(interaction.user.username, interaction.user.displayAvatarURL());