Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set ticket Category #485

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
173 changes: 173 additions & 0 deletions src/commands/admin/announce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
const {
EmbedBuilder,
ApplicationCommandOptionType,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
ComponentType,
} = require("discord.js");

module.exports = {
name: "announce",
description: "Create an announcement in a specified channel & pings @everyone",
cooldown: 0,
category: "MODERATION",
memberpermissions: ['ADMINISTRATOR'],
aliases: ["a"],
usage: "[CHANNEL] [TITLE] [TEXT]",
minArgsCount: 3,
command: {
enabled: true,
},
slashCommand: {
enabled: true,
ephemeral: false,
options: [
{
name: "channel",
description: "The channel to post the announcement in",
type: 7, // CHANNEL
required: true,
},
{
name: "title",
description: "The title of the announcement",
type: 3, // STRING
required: true,
},
{
name: "text",
description: "The text of the announcement(put backwords / n without the space to do line breaks)",
type: 3, // STRING,
required: true,
},
{
name: "color",
description: "The color of the announcement embed (in hex code format)",
type: 3, // STRING
required: false,
},
{
name: "image",
description: "The URL of the image to include in the announcement embed",
type: 3, // STRING,
required: false,
},
{
name: "footer",
description: "The text to display in the footer of the announcement embed",
type: 3, // STRING,
required: false,
},
{
name: "message_id",
description: "The ID of the announcement message to edit",
type: 3, // STRING
required: false,
},
],
},

async messageRun(message, args, data) {
// Check if the command has enough arguments
if (args.length < 3) {
return message.channel.send("Missing required arguments: [CHANNEL] [TITLE] [TEXT]");
}
// Get the channel, title, and text from the command arguments
const channel = message.mentions.channels.first();
const title = args[0];
const image = args[1];
const text = args.slice(2).join(" ");
const color = "#0099ff";
const footer = args[3] || "";
const messageId = args[4];

// Create an embed with the announcement information and color
const embed = new EmbedBuilder()
.setColor(color)
.setTitle(title)
.setDescription(text.replace(/\\n/g, "\n"));

// Add the image to the embed, if provided
if (image) {
embed.setImage(image);
}

// Add the footer to the embed, if provided
if (footer) {
embed.setFooter({ text: footer });
}

// If messageId is provided, edit the existing message
if (messageId) {
try {
const message = await channel.messages.fetch(messageId);
await message.edit({ embeds: [embed] });
await message.channel.send({ content: "@everyone", allowedMentions: { parse: ["everyone"] } });
await message.channel.send(`Announcement embed edited in ${channel}`);
} catch (err) {
console.error(err);
await message.channel.send(`Failed to edit announcement embed in ${channel}`);
}
} else {
// If messageId is not provided, send a new message
const sentMessage = await channel.send({ embeds: [embed] });
await channel.send({ content: "@everyone", allowedMentions: { parse: ["everyone"] } });
await message.channel.send(`Announcement embed sent in ${channel}`);
}
},

async interactionRun(interaction, data) {
// Get the channel, title, and text from the slash command
const channel = interaction.options.getChannel("channel");
const title = interaction.options.getString("title");
const image = interaction.options.getString("image");
const text = interaction.options.getString("text");
const color = interaction.options.getString("color") || "#0099ff";
const footer = interaction.options.getString("footer");
const messageId = interaction.options.getString("message_id");


// Create an embed with the announcement information and color
const embed = new EmbedBuilder()
.setColor(color)
.setTitle(title)
.setDescription(text.replace(/\\n/g, "\n"));

// Add the image to the embed, if provided
if (image) {
embed.setImage(image);
}

// Add the footer to the embed, if provided
if (footer) {
embed.setFooter({ text: footer });
}

// If message_id is provided, edit the existing message
if (messageId) {
try {
const message = await channel.messages.fetch(messageId);
await message.edit({ embeds: [embed] });
await interaction.followUp({
content: `Announcement embed edited in ${channel}`,
ephemeral: false,
});
} catch (err) {
console.error(err);
await interaction.followUp({
content: `Failed to edit announcement embed in ${channel}`,
ephemeral: true,
});
}
} else {
// If message_id is not provided, send a new message
const sentMessage = await channel.send({ embeds: [embed] });
await channel.send({ content: "@everyone", allowedMentions: { parse: ["everyone"] } });
await interaction.followUp({
content: `Announcement embed sent in ${channel}`,
ephemeral: false,
});
}
}
};
129 changes: 129 additions & 0 deletions src/commands/admin/say.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
const {
EmbedBuilder,
ApplicationCommandOptionType,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
ComponentType,
} = require("discord.js");

module.exports = {
name: "say",
description: "Says a message as the bot to a channel you choose",
category: "ADMIN",
botPermissions: ["SendMessages"],
userPermissions: ["ManageMessages"],
slashCommand: {
enabled: true,
ephemeral: true,
description: "Says a message as the bot to a channel you choose",
options: [
{
name: "message",
description: "The message to be sent.",
type: 3,
required: true,
},
{
name: "channel",
description: "The channel where the message will be sent.",
type: 7,
required: false,
},
{
name: "message_id",
description: "The ID of the message to edit or reply to.",
type: 3,
required: false,
},
{
name: "edit",
description: "Whether to edit the message specified by message_id instead of sending a new message.",
type: 5,
required: false,
},
{
name: "ping",
description: "Whether to ping everyone in the channel after sending the message.",
type: 5,
required: false,
},
],
},
async execute(interaction) {
const { options } = interaction;

// Retrieve the message content
const message = options.getString("message").replace(/\\n/g, '\n');

// Retrieve the channel where the message will be sent
const channel = options.getChannel("channel") || interaction.channel;

// Retrieve the message ID to edit or reply to
const message_id = options.getString("message_id");

// Retrieve whether to edit the message specified by message_id
const edit = options.getBoolean("edit");

// Retrieve whether to ping everyone in the channel after sending the message
const ping = options.getBoolean("ping");

try {
// If a message ID is provided, retrieve the message and edit or reply to it
if (message_id) {
const replyMessage = await channel.messages.fetch(message_id).catch(() => null);

if (!replyMessage) {
await interaction.followUp({ content: "Invalid message ID.", ephemeral: true });
}

if (edit) {
await replyMessage.edit(message);
} else {
await replyMessage.reply({ content: `${message}\n${ping ? "@everyone" : ""}`, allowedMentions: { parse: ["everyone", "roles", "users"] } });
}

// Send the final reply
await interaction.followUp({ content: edit ? "Message edited" : "Message sent", ephemeral: true });
} else {
// If no message ID is provided, send a new message
const taggedChannel = options.getChannel("channel");

if (taggedChannel) {
await taggedChannel.send({ content: message, allowedMentions: { parse: ["everyone", "roles", "users"] } });
if (ping) {
setTimeout(async () => {
await taggedChannel.send({ content: "@everyone", allowedMentions: { parse: ["everyone", "roles", "users"] } });
}, 2000); // wait 2 seconds before sending the second message
}
} else {
await interaction.channel.send({ content: message, allowedMentions: { parse: ["everyone", "roles", "users"] } });
if (ping) {
setTimeout(async () => {
await interaction.channel.send({ content: "@everyone", allowedMentions: { parse: ["everyone", "roles", "users"] } });
}, 2000); // wait 2 seconds before sending the second message
}
}


// Send the final reply
await interaction.followUp({ content: "Message sent", ephemeral: true });
}
} catch (error) {
console.error(error);
await interaction.followUp({ content: "An error occurred while processing this command.", ephemeral: true });
}
},

async messageRun(message, args, data) {
const replyEmbed = new EmbedBuilder()
.setTitle("Command Deprecated")
.setDescription("Please use the slash command instead.\n\n**Usage:** /say <message> [channel] [message_id] [edit] [ping]");

return message.reply({ embeds: [replyEmbed], ephemeral: true });
},

async interactionRun(interaction) {
await this.execute(interaction);
},
};
Loading