toowake

Enable Autoreply

Aug 7th, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require("discord.js");
  2. const Schema = require("../../Schemas.js/autoreply");
  3.  
  4. module.exports = {
  5. data: new SlashCommandBuilder()
  6. .setName("autoreply-setup")
  7. .setDescription("Setup the autoreply in your server")
  8. .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
  9. .addStringOption(option => option
  10. .setName("keyword")
  11. .setDescription("the keyword for the reply")
  12. .setRequired(true)
  13. )
  14. .addStringOption(option => option
  15. .setName("reply")
  16. .setDescription("The reply")
  17. .setRequired(true)
  18. ),
  19.  
  20. async execute (interaction, client) {
  21. const embed = new EmbedBuilder();
  22.  
  23. const {options, guild} = interaction;
  24. const g = guild.id;
  25. const keyword = options.getString("keyword");
  26. const reply = options.getString("reply");
  27.  
  28. const data = await Schema.findOne({ Guild: g, Keyword: keyword });
  29.  
  30. if (data) {
  31. embed.setDescription(`There is already a reply for **${keyword}**! | Reply: **${data.Reply}**`).setColor("Red")
  32.  
  33. await interaction.reply({
  34. embeds: [embed],
  35. ephemeral: true
  36. });
  37. } else {
  38. embed.setTitle("Keyword Setup").addFields({ name: "Keyword:", value: `${keyword}`, inline: false}).addFields({ name: "Reply:", value: `${reply}`, inline: false}).setColor("White")
  39.  
  40. await Schema.create({
  41. Guild: g,
  42. Keyword: keyword,
  43. Reply: reply,
  44. });
  45.  
  46. await interaction.reply({ embeds: [embed], ephemeral: true });
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment