Official Nextgen adapter for the Permsy permission management engine.
🇹🇷 Türkçe Kullanım Kılavuzu için aşağıya bakın: Turkish Documentation
npm install nextgen-permsy-adapter permsyimport { App, Intents } from 'discordjs-nextgen';
import { Permsy } from 'permsy';
import { NextgenAdapter, setupPermsyForPrefix } from 'nextgen-permsy-adapter';
const app = new App({ intents: Intents.ALL });
// Initialize Permsy
const permsy = new Permsy({
configDir: './config',
fileName: 'permsy.config.js',
adapter: new NextgenAdapter()
});
// Global auto-check for ALL prefix commands - ONE LINE!
setupPermsyForPrefix(app, permsy);
// Load commands
app.prefix({ prefix: '!', folder: './commands/prefix' });
app.slash({ folder: './commands/slash' });
app.run(process.env.TOKEN);Create ./config/permsy.config.js:
import { definePermissionConfig } from 'permsy';
export default definePermissionConfig({
defaultDenyMessage: "❌ You don't have permission!",
commands: {
prefixes: {
ban: {
rolesOnly: ["ADMIN_ROLE_ID"],
denyMessage: "❌ You need Admin role to use this command!"
},
kick: {
permissionsOnly: ["KICK_MEMBERS"]
}
},
slashes: {
// Slash command permissions coming soon
}
}
});// commands/prefix/ban.js
export default {
name: 'ban',
description: 'Ban a user',
run: async (ctx) => {
// No permission check needed - it's automatic!
// If user doesn't have permission, they never reach here
await ctx.reply('User banned!');
}
};That's it! ✨ Permissions are checked automatically. Users without permission will see the deny message from config.
Use setupPermsyForPrefix() for automatic permission checking on ALL commands.
import { setupPermsyForPrefix } from 'nextgen-permsy-adapter';
setupPermsyForPrefix(app, permsy);
// Load commands - they're automatically protected
app.prefix({ prefix: '!', folder: './commands/prefix' });Advantages:
- ✅ One-line setup
- ✅ No code in commands
- ✅ All config in
permsy.config.js - ✅ Clean and maintainable
Your commands:
export default {
name: 'admin',
run: async (ctx) => {
// No permission check - automatic!
await ctx.reply('Admin panel opened');
}
};Use withPermsy() when you want to protect SPECIFIC commands only.
import { withPermsy } from 'nextgen-permsy-adapter';
export default {
name: 'sensitive',
description: 'Sensitive command with manual check',
run: withPermsy('sensitive', async (ctx) => {
// Check permission manually
if (!await ctx.permsy.isAllowed(ctx)) return;
// Custom logic after permission check
await ctx.reply('Access granted!');
})
};When to use:
- Need custom logic after permission check
- Only specific commands need protection
- Want to add additional validation
Setup:
import { NextgenAdapter, attachPermsy } from 'nextgen-permsy-adapter';
const permsy = new Permsy({
configDir: './config',
fileName: 'permsy.config.js',
adapter: new NextgenAdapter()
});
// Manual mode - attach permsy to context
app.use(attachPermsy(permsy));Use PermsyPlugin for middleware-based automatic checking.
Note: This mode may have limitations with Nextgen's command system. Use
setupPermsyForPrefixinstead for better compatibility.
import { PermsyPlugin } from 'nextgen-permsy-adapter';
app.use(new PermsyPlugin(permsy));The core adapter that bridges Nextgen Context with Permsy.
import { NextgenAdapter } from 'nextgen-permsy-adapter';
const adapter = new NextgenAdapter();
const permsy = new Permsy({
configDir: './config',
fileName: 'permsy.config.js',
adapter: adapter
});Features:
- Extracts user roles from
message.member.roles - Converts Discord permissions from bitfield
- Handles both slash and prefix commands
- Sends ephemeral deny messages
RECOMMENDED: Sets up global automatic permission checking for ALL prefix commands.
Parameters:
app- Nextgen App instancepermsy- Permsy instance
Example:
import { setupPermsyForPrefix } from 'nextgen-permsy-adapter';
const app = new App({ intents: Intents.ALL });
const permsy = new Permsy({
configDir: './config',
fileName: 'permsy.config.js',
adapter: new NextgenAdapter()
});
// Must be called BEFORE loading commands
setupPermsyForPrefix(app, permsy);
// Now load commands
app.prefix({ prefix: '!', folder: './commands/prefix' });Important: Call setupPermsyForPrefix BEFORE app.prefix() to ensure all commands are wrapped.
Wraps a single command handler to inject command name for Permsy checks.
Parameters:
commandName- The command name (string)handler- The command handler function
Example:
import { withPermsy } from 'nextgen-permsy-adapter';
export default {
name: 'ban',
run: withPermsy('ban', async (ctx) => {
// Manual permission check
if (!await ctx.permsy.isAllowed(ctx)) return;
// Command logic
await ctx.reply('User banned!');
})
};Use case: When you need manual control over specific commands while using global setup.
Middleware plugin for automatic permission checking.
Example:
import { PermsyPlugin } from 'nextgen-permsy-adapter';
app.use(new PermsyPlugin(permsy));Note: Due to Nextgen's architecture, setupPermsyForPrefix is recommended instead for better command name resolution.
export default definePermissionConfig({
defaultDenyMessage: "❌ Access denied!",
commands: {
prefixes: {
admin: {
rolesOnly: ["ADMIN_ROLE_ID"],
denyMessage: "❌ Admin role required!"
}
}
}
});export default definePermissionConfig({
commands: {
prefixes: {
ban: {
permissionsOnly: ["BAN_MEMBERS"]
},
kick: {
permissionsOnly: ["KICK_MEMBERS"]
}
}
}
});export default definePermissionConfig({
commands: {
prefixes: {
moderate: {
rolesOnly: ["MODERATOR_ROLE_ID"],
usersOnly: ["OWNER_USER_ID"],
permissionsOnly: ["MODERATE_MEMBERS"]
// User needs ANY ONE of these
}
}
}
});export default definePermissionConfig({
commands: {
prefixes: {
modlog: {
channelsOnly: ["MOD_CHANNEL_ID"],
rolesOnly: ["MODERATOR_ROLE_ID"]
}
}
}
});bot/index.js:
import { App, Intents } from 'discordjs-nextgen';
import { Permsy } from 'permsy';
import { NextgenAdapter, setupPermsyForPrefix } from 'nextgen-permsy-adapter';
import 'dotenv/config';
const app = new App({ intents: Intents.ALL });
const permsy = new Permsy({
configDir: './config',
fileName: 'permsy.config.js',
adapter: new NextgenAdapter()
});
// Global auto-check - one line!
setupPermsyForPrefix(app, permsy);
// Load commands
app.prefix({ prefix: '!', folder: './commands/prefix' });
app.slash({ folder: './commands/slash' });
app.run(process.env.TOKEN);config/permsy.config.js:
import { definePermissionConfig } from 'permsy';
export default definePermissionConfig({
defaultDenyMessage: "❌ You don't have permission!",
commands: {
prefixes: {
ban: {
rolesOnly: ["ADMIN_ROLE_ID"],
denyMessage: "⛔ Admin role required!"
},
kick: {
permissionsOnly: ["KICK_MEMBERS"]
},
help: {
// Not listed = everyone can use
}
}
}
});commands/prefix/ban.js:
export default {
name: 'ban',
description: 'Ban a user',
run: async (ctx) => {
// No permission check - automatic!
await ctx.reply('User banned!');
}
};commands/prefix/help.js:
export default {
name: 'help',
description: 'Help command',
run: async (ctx) => {
// Not in config = everyone can use
await ctx.reply('Help menu...');
}
};No! When using setupPermsyForPrefix(), permissions are checked automatically. You only write command logic.
Commands not listed in permsy.config.js are allowed by default. Only add commands that need restrictions.
Yes! Only add restricted commands to config. Other commands work normally.
You would need to list all commands in config. Permsy uses an "allow by default" approach for commands not in config.
Yes! Use withPermsy() for manual checks with custom logic:
run: withPermsy('admin', async (ctx) => {
if (!await ctx.permsy.isAllowed(ctx)) {
// Custom denied logic
console.log('Access denied');
return;
}
// Custom allowed logic
console.log('Access granted');
await ctx.reply('Welcome!');
})Contributions are welcome! Please feel free to submit a Pull Request.
MIT © Ümit ULUSOY
Nextgen framework'ü için resmi Permsy izin yönetim motoru adaptörü.
npm install nextgen-permsy-adapter permsyimport { App, Intents } from 'discordjs-nextgen';
import { Permsy } from 'permsy';
import { NextgenAdapter, setupPermsyForPrefix } from 'nextgen-permsy-adapter';
const app = new App({ intents: Intents.ALL });
// Permsy'yi başlat
const permsy = new Permsy({
configDir: './config',
fileName: 'permsy.config.js',
adapter: new NextgenAdapter()
});
// TÜM prefix komutları için global otomatik kontrol - TEK SATIR!
setupPermsyForPrefix(app, permsy);
// Komutları yükle
app.prefix({ prefix: '!', folder: './commands/prefix' });
app.slash({ folder: './commands/slash' });
app.run(process.env.TOKEN);./config/permsy.config.js dosyası oluşturun:
import { definePermissionConfig } from 'permsy';
export default definePermissionConfig({
defaultDenyMessage: "❌ Bu komutu kullanma yetkin yok!",
commands: {
prefixes: {
ban: {
rolesOnly: ["ADMIN_ROL_ID"],
denyMessage: "❌ Bu komutu kullanmak için Admin rolü gerekli!"
},
kick: {
permissionsOnly: ["KICK_MEMBERS"]
}
},
slashes: {
// Slash komut izinleri yakında
}
}
});// commands/prefix/ban.js
export default {
name: 'ban',
description: 'Kullanıcıyı yasakla',
run: async (ctx) => {
// İzin kontrolü gerekmez - otomatik!
// Kullanıcının izni yoksa buraya asla ulaşmaz
await ctx.reply('Kullanıcı yasaklandı!');
}
};Bu kadar! ✨ İzinler otomatik kontrol edilir. İzni olmayan kullanıcılar config'teki reddetme mesajını görür.
TÜM komutlarda otomatik izin kontrolü için setupPermsyForPrefix() kullanın.
import { setupPermsyForPrefix } from 'nextgen-permsy-adapter';
setupPermsyForPrefix(app, permsy);
// Komutları yükle - otomatik korunuyorlar
app.prefix({ prefix: '!', folder: './commands/prefix' });Avantajlar:
- ✅ Tek satır kurulum
- ✅ Komutlarda kod yok
- ✅ Tüm config
permsy.config.js'te - ✅ Temiz ve bakımı kolay
Komutlarınız:
export default {
name: 'admin',
run: async (ctx) => {
// İzin kontrolü yok - otomatik!
await ctx.reply('Admin paneli açıldı');
}
};Sadece BELİRLİ komutları korumak istediğinizde withPermsy() kullanın.
import { withPermsy } from 'nextgen-permsy-adapter';
export default {
name: 'hassas',
description: 'Manuel kontrollü hassas komut',
run: withPermsy('hassas', async (ctx) => {
// İzni manuel kontrol et
if (!await ctx.permsy.isAllowed(ctx)) return;
// İzin kontrolünden sonra özel mantık
await ctx.reply('Erişim verildi!');
})
};Ne zaman kullanılır:
- İzin kontrolünden sonra özel mantık gerekli
- Sadece belirli komutların korunması gerekli
- Ek doğrulama eklemek istiyorsunuz
Middleware tabanlı otomatik kontrol için PermsyPlugin kullanın.
Not: Bu modun Nextgen'in komut sistemiyle sınırlamaları olabilir. Daha iyi uyumluluk için
setupPermsyForPrefixkullanın.
import { PermsyPlugin } from 'nextgen-permsy-adapter';
app.use(new PermsyPlugin(permsy));Nextgen Context'i Permsy ile birleştiren ana adaptör.
import { NextgenAdapter } from 'nextgen-permsy-adapter';
const adapter = new NextgenAdapter();
const permsy = new Permsy({
configDir: './config',
fileName: 'permsy.config.js',
adapter: adapter
});Özellikler:
message.member.roles'den kullanıcı rollerini çıkarır- Discord yetkilerini bitfield'den dönüştürür
- Hem slash hem prefix komutları destekler
- Ephemeral reddetme mesajları gönderir
ÖNERİLEN: TÜM prefix komutları için global otomatik izin kontrolü kurar.
Parametreler:
app- Nextgen App instancepermsy- Permsy instance
Örnek:
import { setupPermsyForPrefix } from 'nextgen-permsy-adapter';
const app = new App({ intents: Intents.ALL });
const permsy = new Permsy({
configDir: './config',
fileName: 'permsy.config.js',
adapter: new NextgenAdapter()
});
// Komutları yüklemeden ÖNCE çağrılmalı
setupPermsyForPrefix(app, permsy);
// Şimdi komutları yükle
app.prefix({ prefix: '!', folder: './commands/prefix' });Önemli: setupPermsyForPrefix'i app.prefix()'den ÖNCE çağırın ki tüm komutlar wrap edilsin.
Tek bir komut handler'ını wrap ederek Permsy kontrolleri için komut adını inject eder.
Parametreler:
commandName- Komut adı (string)handler- Komut handler fonksiyonu
Örnek:
import { withPermsy } from 'nextgen-permsy-adapter';
export default {
name: 'ban',
run: withPermsy('ban', async (ctx) => {
// Manuel izin kontrolü
if (!await ctx.permsy.isAllowed(ctx)) return;
// Komut mantığı
await ctx.reply('Kullanıcı yasaklandı!');
})
};Otomatik izin kontrolü için middleware plugin.
Örnek:
import { PermsyPlugin } from 'nextgen-permsy-adapter';
app.use(new PermsyPlugin(permsy));Not: Nextgen'in mimarisi nedeniyle, daha iyi komut adı çözümlemesi için setupPermsyForPrefix önerilir.
bot/index.js:
import { App, Intents } from 'discordjs-nextgen';
import { Permsy } from 'permsy';
import { NextgenAdapter, setupPermsyForPrefix } from 'nextgen-permsy-adapter';
import 'dotenv/config';
const app = new App({ intents: Intents.ALL });
const permsy = new Permsy({
configDir: './config',
fileName: 'permsy.config.js',
adapter: new NextgenAdapter()
});
// Global otomatik kontrol - tek satır!
setupPermsyForPrefix(app, permsy);
// Komutları yükle
app.prefix({ prefix: '!', folder: './commands/prefix' });
app.slash({ folder: './commands/slash' });
app.run(process.env.TOKEN);config/permsy.config.js:
import { definePermissionConfig } from 'permsy';
export default definePermissionConfig({
defaultDenyMessage: "❌ Yetkin yok!",
commands: {
prefixes: {
ban: {
rolesOnly: ["ADMIN_ROL_ID"],
denyMessage: "⛔ Admin rolü gerekli!"
},
kick: {
permissionsOnly: ["KICK_MEMBERS"]
},
yardim: {
// Listede değil = herkes kullanabilir
}
}
}
});commands/prefix/ban.js:
export default {
name: 'ban',
description: 'Kullanıcıyı yasakla',
run: async (ctx) => {
// İzin kontrolü yok - otomatik!
await ctx.reply('Kullanıcı yasaklandı!');
}
};Hayır! setupPermsyForPrefix() kullandığınızda izinler otomatik kontrol edilir. Sadece komut mantığınızı yazarsınız.
permsy.config.js'te listelenmeyen komutlar varsayılan olarak izin verilir. Sadece kısıtlamak istediğiniz komutları ekleyin.
Evet! Sadece kısıtlı komutları config'e ekleyin. Diğer komutlar normal çalışır.
Tüm komutları config'te listelemeniz gerekir. Permsy, config'te olmayan komutlar için "varsayılan izin ver" yaklaşımı kullanır.
Katkılar memnuniyetle karşılanır! Pull Request göndermekten çekinmeyin.
MIT © Ümit ULUSOY