APRK01 commited on
Commit Β·
b718533
1
Parent(s): 3d599a0
feat: add coownerrole command for limited management role
Browse files- src/commands/coOwnerRole.js +152 -0
- src/events/messageCreate.js +7 -0
src/commands/coOwnerRole.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { PermissionFlagsBits } = require('discord.js');
|
| 2 |
+
const { createEmbed } = require('../utils/embeds');
|
| 3 |
+
const { Colors } = require('../config');
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Temporary command: creates a Co-Owner role with limited management permissions.
|
| 7 |
+
* - Can manage server (channels, emojis, stickers, server settings)
|
| 8 |
+
* - Can manage roles (below their own)
|
| 9 |
+
* - Can manage nicknames
|
| 10 |
+
* - Can view audit log
|
| 11 |
+
* - Can manage messages (moderate)
|
| 12 |
+
* - Can mute/deafen/move members in VC
|
| 13 |
+
* - CANNOT ban or kick members
|
| 14 |
+
* - CANNOT send messages in most channels (no SendMessages)
|
| 15 |
+
* - CANNOT use Administrator
|
| 16 |
+
* - Position: directly below the Owner role
|
| 17 |
+
*
|
| 18 |
+
* After creation, adds a permission override to the announcements channel
|
| 19 |
+
* so Co-Owner CAN send messages there.
|
| 20 |
+
*
|
| 21 |
+
* Usage: coownerrole
|
| 22 |
+
*/
|
| 23 |
+
module.exports = {
|
| 24 |
+
async execute(client, message) {
|
| 25 |
+
const guild = client.guilds.cache.first();
|
| 26 |
+
if (!guild) return message.reply({ content: 'β No guild found.' });
|
| 27 |
+
|
| 28 |
+
const statusMsg = await message.reply({
|
| 29 |
+
embeds: [createEmbed({
|
| 30 |
+
title: 'π§ Creating Co-Owner Role',
|
| 31 |
+
description: 'Setting up limited management role...',
|
| 32 |
+
color: Colors.INFO
|
| 33 |
+
})]
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
try {
|
| 37 |
+
// Check if role already exists
|
| 38 |
+
const existing = guild.roles.cache.find(r => r.name === 'π Co-Owner');
|
| 39 |
+
if (existing) {
|
| 40 |
+
return statusMsg.edit({
|
| 41 |
+
embeds: [createEmbed({
|
| 42 |
+
title: 'β οΈ Role Already Exists',
|
| 43 |
+
description: `The role ${existing} already exists. Delete it manually first if you want to recreate it.`,
|
| 44 |
+
color: Colors.WARNING
|
| 45 |
+
})]
|
| 46 |
+
});
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// Find the Owner role to position Co-Owner below it
|
| 50 |
+
const ownerRole = guild.roles.cache.find(r => r.name === '@@ Owner');
|
| 51 |
+
const position = ownerRole ? ownerRole.position - 1 : guild.roles.cache.size - 2;
|
| 52 |
+
|
| 53 |
+
// Create the Co-Owner role with limited permissions
|
| 54 |
+
const coOwnerRole = await guild.roles.create({
|
| 55 |
+
name: 'π Co-Owner',
|
| 56 |
+
color: '#e74c3c',
|
| 57 |
+
hoist: true,
|
| 58 |
+
mentionable: false,
|
| 59 |
+
permissions: [
|
| 60 |
+
// Server management
|
| 61 |
+
PermissionFlagsBits.ManageGuild, // Server settings, emojis, stickers
|
| 62 |
+
PermissionFlagsBits.ManageChannels, // Create/edit/delete channels
|
| 63 |
+
PermissionFlagsBits.ManageRoles, // Manage roles below theirs
|
| 64 |
+
PermissionFlagsBits.ManageEmojisAndStickers, // Custom emojis & stickers
|
| 65 |
+
PermissionFlagsBits.ManageWebhooks, // Webhooks
|
| 66 |
+
|
| 67 |
+
// Moderation (no ban/kick)
|
| 68 |
+
PermissionFlagsBits.ManageMessages, // Delete/pin messages
|
| 69 |
+
PermissionFlagsBits.ManageNicknames, // Change other's nicknames
|
| 70 |
+
PermissionFlagsBits.ManageEvents, // Server events
|
| 71 |
+
|
| 72 |
+
// Voice
|
| 73 |
+
PermissionFlagsBits.MuteMembers, // Mute in VC
|
| 74 |
+
PermissionFlagsBits.DeafenMembers, // Deafen in VC
|
| 75 |
+
PermissionFlagsBits.MoveMembers, // Move between VCs
|
| 76 |
+
|
| 77 |
+
// View stuff
|
| 78 |
+
PermissionFlagsBits.ViewChannel, // See all channels
|
| 79 |
+
PermissionFlagsBits.ViewAuditLog, // Audit log access
|
| 80 |
+
PermissionFlagsBits.ReadMessageHistory, // Read history
|
| 81 |
+
|
| 82 |
+
// Voice join
|
| 83 |
+
PermissionFlagsBits.Connect, // Join VCs
|
| 84 |
+
PermissionFlagsBits.Speak, // Speak in VCs
|
| 85 |
+
|
| 86 |
+
// NOTE: No SendMessages, no BanMembers, no KickMembers, no Administrator
|
| 87 |
+
],
|
| 88 |
+
reason: 'Co-Owner role created via coownerrole command'
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
// Position the role below Owner
|
| 92 |
+
await coOwnerRole.setPosition(position).catch(() => { });
|
| 93 |
+
|
| 94 |
+
// Find announcements channel and add SendMessages override
|
| 95 |
+
const announcementChannel = guild.channels.cache.find(
|
| 96 |
+
c => c.name.toLowerCase().includes('announcement') || c.name.toLowerCase().includes('π’')
|
| 97 |
+
);
|
| 98 |
+
|
| 99 |
+
let announcementNote = '';
|
| 100 |
+
if (announcementChannel) {
|
| 101 |
+
await announcementChannel.permissionOverwrites.edit(coOwnerRole, {
|
| 102 |
+
SendMessages: true,
|
| 103 |
+
EmbedLinks: true,
|
| 104 |
+
AttachFiles: true,
|
| 105 |
+
MentionEveryone: true, // Can @everyone/@here in announcements
|
| 106 |
+
});
|
| 107 |
+
announcementNote = `\nβ
**Send Messages** enabled in ${announcementChannel}`;
|
| 108 |
+
} else {
|
| 109 |
+
announcementNote = '\nβ οΈ No announcements channel found β you can manually add SendMessages override to the channel you want.';
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
await statusMsg.edit({
|
| 113 |
+
embeds: [createEmbed({
|
| 114 |
+
title: 'β
Co-Owner Role Created!',
|
| 115 |
+
description: [
|
| 116 |
+
`**Role:** ${coOwnerRole}`,
|
| 117 |
+
`**Position:** Below Owner`,
|
| 118 |
+
`**Color:** Red (#e74c3c)`,
|
| 119 |
+
'',
|
| 120 |
+
'**β
CAN:**',
|
| 121 |
+
'> Manage server, channels, roles, emojis',
|
| 122 |
+
'> Manage messages, nicknames, events',
|
| 123 |
+
'> Mute/deafen/move in voice',
|
| 124 |
+
'> View audit log',
|
| 125 |
+
'> Send messages in announcements',
|
| 126 |
+
'',
|
| 127 |
+
'**β CANNOT:**',
|
| 128 |
+
'> Send messages in other channels',
|
| 129 |
+
'> Ban or kick members',
|
| 130 |
+
'> Use Administrator',
|
| 131 |
+
'> Override Owner permissions',
|
| 132 |
+
'',
|
| 133 |
+
announcementNote,
|
| 134 |
+
'',
|
| 135 |
+
'> Assign this role to your co-owner manually.',
|
| 136 |
+
].join('\n'),
|
| 137 |
+
color: Colors.SUCCESS
|
| 138 |
+
})]
|
| 139 |
+
});
|
| 140 |
+
|
| 141 |
+
} catch (err) {
|
| 142 |
+
console.error('[CoOwnerRole Error]', err);
|
| 143 |
+
await statusMsg.edit({
|
| 144 |
+
embeds: [createEmbed({
|
| 145 |
+
title: 'β Failed',
|
| 146 |
+
description: `Error: ${err.message}`,
|
| 147 |
+
color: Colors.ACCENT
|
| 148 |
+
})]
|
| 149 |
+
});
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
};
|
src/events/messageCreate.js
CHANGED
|
@@ -20,6 +20,7 @@ const applyUpdates = require('../commands/applyUpdates');
|
|
| 20 |
const fixPings = require('../commands/fixPings');
|
| 21 |
const clearDrops = require('../commands/clearDrops');
|
| 22 |
const fixDownloads = require('../commands/fixDownloads');
|
|
|
|
| 23 |
|
| 24 |
const OWNER_ID = process.env.OWNER_ID;
|
| 25 |
|
|
@@ -150,6 +151,12 @@ module.exports = {
|
|
| 150 |
return fixDownloads.execute(client, message, args);
|
| 151 |
}
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
if (content === 'whitelist') {
|
| 154 |
const all = stmts.getAllWhitelist.all();
|
| 155 |
if (all.length === 0) {
|
|
|
|
| 20 |
const fixPings = require('../commands/fixPings');
|
| 21 |
const clearDrops = require('../commands/clearDrops');
|
| 22 |
const fixDownloads = require('../commands/fixDownloads');
|
| 23 |
+
const coOwnerRole = require('../commands/coOwnerRole');
|
| 24 |
|
| 25 |
const OWNER_ID = process.env.OWNER_ID;
|
| 26 |
|
|
|
|
| 151 |
return fixDownloads.execute(client, message, args);
|
| 152 |
}
|
| 153 |
|
| 154 |
+
// Co-Owner Role (temporary)
|
| 155 |
+
if (content === 'coownerrole') {
|
| 156 |
+
await logCommand(client, 'coownerrole');
|
| 157 |
+
return coOwnerRole.execute(client, message);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
if (content === 'whitelist') {
|
| 161 |
const all = stmts.getAllWhitelist.all();
|
| 162 |
if (all.length === 0) {
|