Ryuu Potato
Ryuu Potato

Reputation: 39

TypeError: Cannot read properties of undefined (reading 'start')

Giveaway.js

I am getting this error, and I don't know how to fix it, but tutorials use the same thing and don't get this error.

Cannot read properties of undefined (reading 'start')

My code:

case 'start': {
  const gchannel = options.getChannel('channel') || interaction.channel;
  const duration = options.getString('duration');
  const winnerCount = options.getInteger('winners');
  const prize = options.getString('prize');

  client.giveawaysManager
    .start(gchannel, {
      duration: ms(duration),
      winnerCount,
      prize,
      messages: {
        giveaway: '🎉 **GIVEAWAY STARTED**🎉',
        giveawayEnded: '🎊 **GIVEAWAY ENDED** 🎊',
        winMessage: 'Congratulations, {winners}! You won **{this.prize}**!',
      },
    })
    .then(async () => {
      successembed.setDescription('giveaway successfully started.');
      wait(4000);
      interaction.reply({ embeds: [successembed], ephemeral: true });
    })
    .catch((err) => {
      errorembed.setDescription(`An error has occured \n\`${err}\``);
      wait(4000);
      interaction.reply({ embeds: [errorembed], ephemeral: true });
    });
}

The error is in:

client.giveawaysManager.start(gchannel, {
  duration: ms(duration),
  winnerCount,
  prize,
  messages: {
    giveaway: '🎉 **GIVEAWAY STARTED**🎉',
    giveawayEnded: '🎊 **GIVEAWAY ENDED** 🎊',
    winMessage: 'Congratulations, {winners}! You won **{this.prize}**!',
  },
})

Upvotes: 0

Views: 4381

Answers (1)

19mike95
19mike95

Reputation: 506

It is not client.giveawaysManager, it needs to be constructed by itself:

manager= new GiveawaysManager(client, options(opt), init(opt));

And then it is called this way:

manager.start(gchannel, {
  duration: ms(duration),
  winnerCount,
  prize,
  messages: {
    giveaway: '🎉 **GIVEAWAY STARTED**🎉',
    giveawayEnded: '🎊 **GIVEAWAY ENDED** 🎊',
    winMessage: 'Congratulations, {winners}! You won **{this.prize}**!',
  },
})

DOC: https://discord-giveaways.js.org/GiveawaysManager.html

Upvotes: 1

Related Questions