Skip to content

Commit

Permalink
[Update] Added interaction functionality for welcome and leave
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Nov 18, 2021
1 parent 0f1cb08 commit 49793df
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 19 deletions.
81 changes: 72 additions & 9 deletions commands/Config/leavechannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
embeds: [
embedMessage(
"RED",
`You did not provide enough arguments!\n See \`${defaultPrefix}h leave\` for more info!`
`You did not provide enough arguments!\n See \`${defaultPrefix}h leave\` for more info!`
),
],
});
Expand All @@ -39,7 +39,7 @@ module.exports = {
embeds: [
embedMessage(
"RED",
`This is not a valid operation.\n Please specify whether you want to \`add || remove\` a custom leave channel!`
`This is not a valid operation.\n Please specify whether you want to \`add || remove\` a custom leave channel!`
),
],
});
Expand All @@ -49,7 +49,7 @@ module.exports = {
embeds: [
embedMessage(
"RED",
`You netiher mentioned the text channel nor its name!`
`You netiher mentioned the text channel nor its name!`
),
],
});
Expand All @@ -59,7 +59,7 @@ module.exports = {
embeds: [
embedMessage(
"RED",
`This is not a valid operation. See \`${defaultPrefix}h leave\` for more info \n Please specify whether you want to \`add || remove\` a custom leave channel!`
`This is not a valid operation. See \`${defaultPrefix}h leave\` for more info \n Please specify whether you want to \`add || remove\` a custom leave channel!`
),
],
});
Expand All @@ -75,7 +75,7 @@ module.exports = {
embeds: [
embedMessage(
"RED",
`No text channel with this name or mention was found!`
`No text channel with this name or mention was found!`
),
],
});
Expand All @@ -91,7 +91,7 @@ module.exports = {
embeds: [
embedMessage(
"#9dcc37",
`A custom leave message has been set successfully!`
`A custom leave message has been set successfully!`
),
],
});
Expand All @@ -102,7 +102,7 @@ module.exports = {
embeds: [
embedMessage(
"#9dcc37",
`Leave message channel has been resetted to default!`
`Leave message channel has been resetted to default!`
),
],
});
Expand All @@ -111,7 +111,7 @@ module.exports = {
} catch (err) {
client.logger.error(err.message, "error");
await message.channel.send({
embeds: [embedMessage("RED", `Could not perform this action`)],
embeds: [embedMessage("RED", `Could not perform this action`)],
});
}
},
Expand All @@ -134,5 +134,68 @@ module.exports = {
.setDescription("New text channel")
.setRequired(true)
),
async execute(interaction, client) {},
async execute(interaction, client) {
await interaction.deferReply();
const action = interaction.options.getString("action");
const newLeaveChannel = interaction.options.getChannel("channel");

if (
!interaction.member.permissions.has("MANAGE_GUILD") ||
!interaction.member.permissions.has("ADMINISTRATOR")
) {
return await interaction.followUp({
embeds: [
embedMessage(
"RED",
`❌ You do not have permission to set a custom leave channel!`
),
],
});
}

if (newLeaveChannel.type !== "GUILD_TEXT")
return await interaction.followUp({
embeds: [
embedMessage(
"RED",
`❌ You can only set text channels as custom leave message channel!`
),
],
});

try {
switch (action) {
case "add":
await client.db.set(
`leave_${interaction.guildId}`,
`${newLeaveChannel.id}`
);
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ A custom leave message has been set successfully!`
),
],
});
break;
case "remove":
await client.db.delete(`leave_${interaction.guildId}`);
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ Leave message channel has been resetted to default!`
),
],
});
break;
}
} catch (err) {
client.logger.error(err.message, "error");
await interaction.followUp({
embeds: [embedMessage("RED", `❌ Could not perform this action`)],
});
}
},
};
83 changes: 73 additions & 10 deletions commands/Config/welcomechannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
embeds: [
embedMessage(
"RED",
`You did not provide enough arguments!\n See \`${defaultPrefix}h welcome\` for more info!`
`You did not provide enough arguments!\n See \`${defaultPrefix}h welcome\` for more info!`
),
],
});
Expand All @@ -39,7 +39,7 @@ module.exports = {
embeds: [
embedMessage(
"RED",
`This is not a valid operation.\n Please specify whether you want to \`add || remove\` a custom weclome channel!`
`This is not a valid operation.\n Please specify whether you want to \`add || remove\` a custom weclome channel!`
),
],
});
Expand All @@ -49,7 +49,7 @@ module.exports = {
embeds: [
embedMessage(
"RED",
`You netiher mentioned the text channel nor its name!`
`You netiher mentioned the text channel nor its name!`
),
],
});
Expand All @@ -59,7 +59,7 @@ module.exports = {
embeds: [
embedMessage(
"RED",
`This is not a valid operation. See \`${defaultPrefix}h welcome\` for more info \n Please specify whether you want to \`add || remove\` a custom weclome channel!`
`This is not a valid operation. See \`${defaultPrefix}h welcome\` for more info \n Please specify whether you want to \`add || remove\` a custom weclome channel!`
),
],
});
Expand All @@ -75,7 +75,7 @@ module.exports = {
embeds: [
embedMessage(
"RED",
`No text channel with this name or mention was found!`
`No text channel with this name or mention was found!`
),
],
});
Expand All @@ -91,7 +91,7 @@ module.exports = {
embeds: [
embedMessage(
"#9dcc37",
`A custom welcome message has been set successfully!`
`A custom welcome message has been set successfully!`
),
],
});
Expand All @@ -102,7 +102,7 @@ module.exports = {
embeds: [
embedMessage(
"#9dcc37",
`Welcome message channel has been resetted to default!`
`Welcome message channel has been resetted to default!`
),
],
});
Expand All @@ -124,8 +124,8 @@ module.exports = {
option
.setName("action")
.setDescription("add or delete custom welcome channel")
.addChoice("Add", "set")
.addChoice("Remove", "delete")
.addChoice("Add", "add")
.addChoice("Remove", "remove")
.setRequired(true)
)
.addChannelOption((option) =>
Expand All @@ -134,5 +134,68 @@ module.exports = {
.setDescription("New text channel")
.setRequired(true)
),
async execute(interaction, client) {},
async execute(interaction, client) {
await interaction.deferReply();
const action = interaction.options.getString("action");
const newwelcomeChannel = interaction.options.getChannel("channel");

if (
!interaction.member.permissions.has("MANAGE_GUILD") ||
!interaction.member.permissions.has("ADMINISTRATOR")
) {
return await interaction.followUp({
embeds: [
embedMessage(
"RED",
`❌ You do not have permission to set a custom welcome channel!`
),
],
});
}

if (newwelcomeChannel.type !== "GUILD_TEXT")
return await interaction.followUp({
embeds: [
embedMessage(
"RED",
`❌ You can only set text channels as custom welcome message channel!`
),
],
});

try {
switch (action) {
case "add":
await client.db.set(
`welcome_${interaction.guildId}`,
`${newwelcomeChannel.id}`
);
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ A custom welcome message has been set successfully!`
),
],
});
break;
case "remove":
await client.db.delete(`welcome_${interaction.guildId}`);
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ Welcome message channel has been resetted to default!`
),
],
});
break;
}
} catch (err) {
client.logger.error(err.message, "error");
await interaction.followUp({
embeds: [embedMessage("RED", `❌ Could not perform this action`)],
});
}
},
};

0 comments on commit 49793df

Please sign in to comment.