Pix / utils /misc.ts
cybergamer0123's picture
okay?
b1f8189
import { Message, GuildMember, PermissionFlagsBits } from "discord.js";
import axios from "axios";
export const generateContent = async (prompt: string, sysprompt: string = ""): Promise<any> => {
return `You said ${prompt}`;
};
export const Require = async (message: Message, permission: string): Promise<boolean> => {
// Check if the command is used in a guild (not DMs)
if (!message.guild) {
await message.reply({
content: "Let's not use this command in DMs.",
});
return false;
}
// Retrieve the member object
const member = message.guild.members.cache.get(message.author.id);
if (!member) {
await message.reply({
content: "Sorry mate, I could not see what moderation permissions you have.",
});
return false;
}
// Initialize permission check
let hasPermission = false;
// Check the specified permission
switch (permission) {
case "message":
hasPermission = member.permissions.has(PermissionFlagsBits.ManageMessages);
if (!hasPermission) {
await message.reply({
content: `You **__NEED__** the \`MANAGE ${permission.toUpperCase()}\` permission to **__execute__** this command.`,
});
}
break;
case "guild":
hasPermission = member.permissions.has(PermissionFlagsBits.ManageGuild);
if (!hasPermission) {
await message.reply({
content: `You **__NEED__** the \`MANAGE ${permission.toUpperCase()}\` permission to **__execute__** this command.`,
});
}
break;
default:
await message.reply("Invalid permission type.");
return false;
}
// If the user lacks permissions, schedule the message to be deleted
if (!hasPermission) {
setTimeout(() => {
message.delete().catch(() => {}); // Handle errors gracefully
}, 5000);
}
return hasPermission;
};
export enum perms {
manage_MESSAGE = "message",
manage_GUILD = "guild"
}