Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.

Button to delete Piracy message (for staff) #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions commands/piracy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { MessageEmbed } = require('discord.js');
const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');

const row = new MessageActionRow().addComponents(new MessageButton()
.setCustomId('hide')
.setStyle('SECONDARY')
.setEmoji('❌'))
const text = `Piracy is not allowed in this server. Please read <#521711544925552642>!
We will only support the dumping of games you own.
If you don't want to do that, find out what to do yourself.`;
Expand All @@ -14,6 +17,6 @@ module.exports = {
.setName('piracy')
.setDescription('Explains our piracy policy'),
async execute(interaction) {
return interaction.reply({ embeds: [embed] });
return interaction.reply({ embeds: [embed] ,components:[row]});
},
};
65 changes: 44 additions & 21 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
module.exports = {
name: 'interactionCreate',
/**
*
* @param {import('discord.js').CommandInteraction} interaction
* @returns
*/
async execute(interaction) {
if (!interaction.isCommand()) return;
name: "interactionCreate",
/**
*
* @param {import('discord.js').CommandInteraction} interaction
* @returns
*/
async execute(interaction) {
if (interaction.isButton()) {
if (interaction.customId === "hide") {
if (
interaction.member.roles.cache.some((r) => r.name === "Admin") ||
interaction.member.roles.cache.some((r) => r.name === "Moderator") ||
interaction.member.roles.cache.some((r) => r.name === "Support Staff")
) {
await interaction.deferUpdate();
interaction.deleteReply();
} else {
interaction.reply({
content: `Nice try! Only staff can delete this message`,
ephemeral: true,
});
}
}
}
if (!interaction.isCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);
const command = interaction.client.commands.get(interaction.commandName);

if (!command) return;
if (!command) return;

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.deferred || interaction.replied) {
return interaction.editReply({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
return interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
},
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.deferred || interaction.replied) {
return interaction.editReply({
content: "There was an error while executing this command!",
ephemeral: true,
});
} else {
return interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
}
}
},
};