DudeThatsErin

Untitled

May 1st, 2021
695
19 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2. const connection = require('../database.js');
  3.  
  4. module.exports = {
  5.     name: 'edit-challenge',
  6.     description: 'This gives **mods** the ability to edit the challenge questions that get asked.',
  7.     aliases: ['editchal', 'editchallenge', 'modify-challenge', 'ec'],
  8.     usage: '!edit-challenge [challenge number] <number of points> [message ID]',
  9.     async execute (message, args) {
  10.  
  11.         if(!message.member.hasPermission("MANAGE_MESSAGES") ){
  12.             message.channel.send('You can\'t use this command, only mods can use this command. If you are a mod and you are seeing this, it is because only users with the \`MANAGE_MESSAGES\` permission can use this command.');
  13.             return;
  14.         } else {
  15.             let day = args[0];
  16.             let title = args.slice(1).join(' ');
  17.  
  18.             const result = await connection.query(
  19.                 `SELECT * FROM Challenge WHERE guildId = ?;`,
  20.                 [message.guild.id]
  21.             );
  22.             const msgId = result[0][0].msgId;
  23.             const channel = result[0][0].channelD;
  24.  
  25.             console.log(result);
  26.             console.log(result[0][0].channelD);
  27.             console.log(result[0][0].msgId);
  28.  
  29.             channel.messages.fetch(msgId).then(message => {
  30.                 if(message) message.edit(embed);
  31.             });
  32.  
  33.             connection.query(
  34.                 `UPDATE Challenge SET title = ? WHERE msgId = ? AND guildId = ?`,
  35.                 [title, msg, message.guild.id]
  36.             );
  37.  
  38.             let embed = new Discord.MessageEmbed()
  39.                 .setColor('BLUE')
  40.                 .setTitle(`${day}`)
  41.                 .setDescription(`${title}`)
  42.                 .setFooter('Run the s.submit to submit answers to this challenge.');
  43.  
  44.             message.delete();
  45.             message.reply('Thanks! I have updated the message you gave me the ID for.');
  46.  
  47.         }
  48.  
  49.  
  50.     }
  51. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×