toowake

announcement command (JavaScript)

Mar 21st, 2023
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. const { SlashCommandBuilder, EmbedBuilder, PermissionsBitField, ChannelType} = require("discord.js");
  2.  
  3. module.exports = {
  4. data: new SlashCommandBuilder()
  5. .setName("announce")
  6. .setDescription("Announce something in the server!")
  7. .addChannelOption(option => option
  8. .setName("channel")
  9. .setDescription("The announcement channel")
  10. .addChannelTypes(ChannelType.GuildAnnouncement)
  11. .setRequired(true)
  12. )
  13. .addStringOption(option => option
  14. .setName("title")
  15. .setDescription("The title of the announcement")
  16. .setRequired(false)
  17. )
  18. .addStringOption(option => option
  19. .setName("description")
  20. .setDescription("The description of this announcement")
  21. .setRequired(false)
  22. ),
  23.  
  24. async execute (interaction, client) {
  25. const channelID = interaction.options.getChannel("channel");
  26.  
  27. const desc = interaction.options.getString("description") || "test announce";
  28.  
  29. const title = interaction.options.getString("title") || "NEW ANNOUNCEMENT!";
  30.  
  31. const userx = interaction.user.id;
  32.  
  33. const embed = new EmbedBuilder()
  34. .setTitle(`${title}`)
  35. .setDescription(`${desc}`)
  36. .addFields({ name: "Moderator:", value: `<@${userx}>`, inline: false})
  37. .setTimestamp()
  38.  
  39. const channel = client.channels.cache.get(`${channelID.id}`);
  40.  
  41. channel.send({
  42. embeds: [embed]
  43. }).catch(err => {
  44. return;
  45. });
  46.  
  47. return interaction.reply({content: `The Announcement has been send in <#${channelID.id}>`, ephemeral: true});
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment