toowake

impersonate.js

Aug 7th, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. const { SlashCommandBuilder } = require("discord.js");
  2.  
  3. module.exports = {
  4. data: new SlashCommandBuilder()
  5. .setName("impersonate")
  6. .setDescription("impersonate a user with a webhook")
  7. .addUserOption(option => option
  8. .setName("user")
  9. .setDescription("The user you want to impersonate")
  10. .setRequired(true)
  11. )
  12. .addStringOption(option => option
  13. .setName("message")
  14. .setDescription("the message")
  15. .setRequired(true)
  16. ),
  17.  
  18. async execute (interaction) {
  19. //define member and message
  20. const member = interaction.options.getUser("user");
  21. const message = interaction.options.getString("message");
  22.  
  23. //if includes everone or here
  24. if (message.includes('@everyone') || message.includes('@here')) return await interaction.reply({
  25. content: `You cannot mention everyone/here with this command`,
  26. ephemeral: true
  27. });
  28.  
  29. //create the webhook and message, and then delete webhook
  30. await interaction.channel.createWebhook({
  31. name: member.username,
  32. avatar: member.displayAvatarURL({ dynamic: true })
  33. }).then((webhook) => {
  34. webhook.send({content: message});
  35. setTimeout(() => {
  36. webhook.delete();
  37. }, 3000)
  38. });
  39.  
  40. //send an ephemeral message to verify that the webhook send this message
  41. await interaction.reply({
  42. content: `<@${member.id}> has been impersonated below!`,
  43. ephemeral: true
  44. });
  45. }
  46. }
Add Comment
Please, Sign In to add comment