#Problem ReferenceError message is not defined

1 messages · Page 1 of 1 (latest)

kind chasm
#

Hi, I have this problem: ReferenceError: message is not defined. This is the strings: if (interaction.commandName === 'clear') {
const user = message.mentions.users.first();
let amount = !!parseInt(message.content.split(' ')[1]) ? parseInt(message.content.split(' ')[1]) : parseInt(message.content.split(' ')[2])
amount = Math.floor(amount + 1);
if (!amount) return message.reply('You need to specify an amount.');
if (!amount && !user) return message.reply('You need to specify a user and an amount.');

  messages.channel.messages.fetch({
   limit: 100,
  }).then((messages) => {
   if (user) {
   const filterBy = user ? user.id : Client.user.id;
   messages = messages.filter(m => m.author.id === filterBy).array().slice(0, amount);
   } else {
      messages = amount;
   }
      message.channel.bulkDelete(messages).catch(error => console.log(error.stack));
  });
}
#

how to resolve this?

icy sedge
#

Well message is not defined, is different to is undefined

#

So define it

kind chasm
#

yes but how?

icy sedge
#

const message = '123'

#

You define it, however you need the message to be

#

oh, I see, you've taken a "text command" and copy pasted it for a Slash Command haven't you?

kind chasm
#

yes

icy sedge
#

So that's not gonna work out of the box

kind chasm
#

how can I resolve?

icy sedge
#

You go from text splitting and manipulatiuon, to options instead

#

e.g...

#

!help ban
becomes:
/help with:ban

#

e.g. you have an const with = interaction.options.getString('with')

#

My Advice, make a slash command from scratch, learn how they work, then you'll be in a better position to update your text ones to slash

kind chasm
icy sedge
gilded vortexBOT