RASKOLOV

InteractionCreate

Feb 21st, 2024
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. const { CommandInteraction } = require('discord.js');
  2. const { ButtonInteraction } = require('discord.js');
  3. const { InteractionType } = require('discord.js');
  4.  
  5. module.exports = {
  6. name: 'interactionCreate',
  7. /**
  8. * @param { CommandInteraction } interaction
  9. * @param { ButtonInteraction } interaction
  10. */
  11. execute(interaction, client) {
  12. if(interaction.isChatInputCommand()) {
  13. const command = client.commands.get(interaction.commandName);
  14. if(!command) return;
  15. try {
  16. command.execute(interaction, client);
  17. } catch(error) {
  18. console.log(error);
  19. interaction.reply({content: 'Something went wrong while executing this interaction.', ephemeral: true}).catch(error => {return});
  20. }
  21. } else if(interaction.isButton()) {
  22. const Button = client.buttons.get(interaction.customId);
  23. if(!Button) return;
  24. try {
  25. Button.execute(interaction, client);
  26. } catch(error) {
  27. console.log(error);
  28. interaction.reply({content: 'Something went wrong while executing this interaction.', ephemeral: true}).catch(error => {return});
  29. }
  30. } else if(interaction.isStringSelectMenu()) {
  31. const { selectMenus } = client;
  32. const menu = selectMenus.get(interaction.customId);
  33. if(!menu) return;
  34. try {
  35. menu.execute(interaction, client);
  36. } catch(error) {
  37. console.log(error);
  38. interaction.reply({content: 'Something went wrong while executing this interaction.', ephemeral: true}).catch(error => {return});
  39. }
  40.  
  41. } else if(interaction.type == InteractionType.ModalSubmit) {
  42. const { modals } = client;
  43. const modal = modals.get(interaction.customId);
  44. if(!modal) return;
  45. try {
  46. modal.execute(interaction, client);
  47. } catch(error) {
  48. console.log(error);
  49. interaction.reply({content: 'Something went wrong while executing this interaction.', ephemeral: true}).catch(error => {return});
  50. }
  51.  
  52. } else if(interaction.isContextMenuCommand()) {
  53. const { commands } = client;
  54. const { commandName } = interaction;
  55. const contextCommand = commands.get(commandName);
  56. if (!contextCommand) return;
  57. try {
  58. contextCommand.execute(interaction, client);
  59. } catch (error) {
  60. console.log(error);
  61. interaction.reply({content: 'Something went wrong while executing this interaction.', ephemeral: true}).catch(error => {return});
  62. }
  63. }
  64. }}
Add Comment
Please, Sign In to add comment