title: Discord.js (v12) Giveaway Command --> Error: Cannot read property 'hasPermission' of undefined
body: <p>Im trying to code my own discord bot and now i wanna make a giveaway command...
  I researched for an example code and found this. I tested it and it's not working...</p>
  <pre><code>const ms = require('ms');
  const chalk = require('chalk');
  const consolewords = chalk.keyword('white');
  const consoleerrcmds = chalk.keyword('yellow');
  
  module.exports = {
      name: 'gcreate',
      description: 'Start a giveaway',
      cooldown: 5,
      args: true,
      guildOnly: true,
      usage: '|Channel| [Duration] (Winner) {Prize}',
      permission: 'Operator',
      id: 115,
      execute: async (client, message, args) =&gt; {
  
          if (message.member.hasPermission(['SEND_TTS_MESSAGES'])) {
  
              const giveawayChannel = message.mentions.channels.first();
              if(!giveawayChannel) {
                  return message.channel.send(':x: You have to mention a valid channel!');
              }
  
              const giveawayDuration = args[1];
              if(!giveawayDuration || isNaN(ms(giveawayDuration))) {
                  return message.channel.send(':x: You have to specify a valid duration!');
              }
              const giveawayNumberWinners = args[2];
              if(isNaN(giveawayNumberWinners) || (parseInt(giveawayNumberWinners) &lt;= 0)) {
                  return message.channel.send(':x: You have to specify a valid number of winners!');
              }
  
              const giveawayPrize = args.slice(3).join(' ');
              if(!giveawayPrize) {
                  return message.channel.send(':x: You have to specify a valid prize!');
              }
  
              client.giveawaysManager.start(giveawayChannel, {
                  time: ms(giveawayDuration),
                  prize: giveawayPrize,
                  winnerCount: giveawayNumberWinners,
                  hostedBy: client.config.hostedBy ? message.author : null,
                  messages: {
                      giveaway: (client.config.everyoneMention ? '@everyone\n\n' : '') + ' **GIVEAWAY** ',
                      giveawayEnded: (client.config.everyoneMention ? '@everyone\n\n' : '') + ' **GIVEAWAY ENDED** ',
                      timeRemaining: 'Time remaining: **{duration}**!',
                      inviteToParticipate: 'React with  to participate!',
                      winMessage: 'Congratulations, {winners}! You won **{prize}**!',
                      embedFooter: 'Giveaways',
                      noWinner: 'Giveaway cancelled, no valid participations.',
                      hostedBy: 'Hosted by: {user}',
                      winners: 'winner(s)',
                      endedAt: 'Ended at',
                      units: {
                          seconds: 'seconds',
                          minutes: 'minutes',
                          hours: 'hours',
                          days: 'days',
                          pluralS: false,
                      },
                  },
              });
  
              message.channel.send(`Giveaway started in ${giveawayChannel}!`);
          }
          if (!message.member.hasPermission(['SEND_TTS_MESSAGES'])) {
              message.channel.send('You don\'t have the permission to do that!');
              console.log(consolewords('[CMD]: ') + consoleerrcmds(`${message.author.username} wanted to create a giveaway but didn't have the permission!`));
          }
  
      },
  };
  </code></pre>
  <p>I'm getting this error code: <code>UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'hasPermission' of undefined</code>.
  I'm not sure what is wrong because the same if-statement works on another commands!</p>
  <p>Thank you in advance for helping!</p>
  <p>Ps: I installed all packages. So there shouldn't be a problem!</p>