Skip to content

Commit

Permalink
[Fix] return if channel not found, search by id and name and added in…
Browse files Browse the repository at this point in the history
…teraction command functionality
  • Loading branch information
naseif committed Nov 3, 2021
1 parent 687a81c commit cc861e8
Showing 1 changed file with 121 additions and 3 deletions.
124 changes: 121 additions & 3 deletions commands/Admin/nuke.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,41 @@ module.exports = {

try {
const channel = message.guild.channels.cache.find(
(channel) => channel.id === args[0]
(channel) => channel.id === args[0] || channel.name === args[0]
);

if (!channel) {
return await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
`❌ A text channel with this ID was not found!`
),
],
});
}
const channelClone = await channel.clone();
const nukeChannel = await channel.delete();
await channelClone.setPosition(nukeChannel.rawPosition);
const newCreatedChannel = message.guild.channels.cache.find(
(channel) => channel.name === channelClone.name
);
return await newCreatedChannel.send({
await newCreatedChannel.send({
content: "✅ | Channel has been nuked :D",
files: ["https://c.tenor.com/Naz32m5Pp6YAAAAC/nuke.gif"],
});
return await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
`Text Channel ` +
"`" +
`${channelClone.name}` +
"`" +
` has been nuked!`
),
],
});
} catch (err) {
client.logger(err.message, "error");
return await message.channel.send({
Expand All @@ -72,6 +95,101 @@ module.exports = {
.setName("nuke")
.setDescription(
"Deletes a text channel and recreates it with same permissions"
)
.addStringOption((option) =>
option
.setName("id")
.setDescription("id of the channel")
.setRequired(false)
),
async execute(interaction, client) {},
async execute(interaction, client) {
await interaction.deferReply();

const id = interaction.options.getString("id");

if (!interaction.member.permissions.has("ADMINISTRATOR"))
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`❌ You do not have permission to nuke this channel.\nOnly Server Admins have the permission to perform this action`
),
],
});

if (!id) {
try {
const cloneChannel = await interaction.channel.clone();
const deleteChannel = await interaction.channel.delete();
await cloneChannel.setPosition(deleteChannel.rawPosition);
const newChannel = interaction.guild.channels.cache.find(
(channel) => channel.name === cloneChannel.name
);
return await newChannel.send({
content: "✅ | Channel has been nuked :D",
files: ["https://c.tenor.com/Naz32m5Pp6YAAAAC/nuke.gif"],
});
} catch (err) {
client.logger(err.message, "error");
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`❌ | Could not nuke the Channel!\nError: ${err.message}`
),
],
});
}
}

try {
const channel = interaction.guild.channels.cache.find(
(channel) => channel.id === id || channel.name === id
);

if (!channel) {
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`❌ A text channel with this ID was not found!`
),
],
});
}

const channelClone = await channel.clone();
const nukeChannel = await channel.delete();
await channelClone.setPosition(nukeChannel.rawPosition);
const newCreatedChannel = interaction.guild.channels.cache.find(
(channel) => channel.name === channelClone.name
);
await newCreatedChannel.send({
content: "✅ | Channel has been nuked :D",
files: ["https://c.tenor.com/Naz32m5Pp6YAAAAC/nuke.gif"],
});
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`Text Channel ` +
"`" +
`${channelClone.name}` +
"`" +
` has been nuked!`
),
],
});
} catch (err) {
client.logger(err.message, "error");
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`❌ | Could not nuke the Channel!\nError: ${err.message}`
),
],
});
}
},
};

0 comments on commit cc861e8

Please sign in to comment.