Admin Panel
Exemplo de painel administrativo completo
Funcionalidades
- Dashboard com estatísticas
- Gerenciamento de usuários
- Criação de canais
- Gerenciamento de roles
- Sistema de logs
Código
typescript
1import { 2 FlowRegistry, FlowEngine, MemoryStore, createServer,3 Container, Section, TextDisplay, Button, ActionRow, Separator,4 DiscordAPI5} from 'discord-flow';6 7const registry = new FlowRegistry();8const engine = new FlowEngine(registry, new MemoryStore());9const discord = new DiscordAPI({ token: process.env.DISCORD_TOKEN! });10 11registry.define('admin', (flow) => {12 flow.start('idle');13 14 flow.state('idle')15 .on.command({16 name: 'admin',17 description: 'Abre o painel de administração'18 }, async (ctx) => {19 const guild = await discord.getGuild(ctx.guild!.id);20 const members = await discord.getMembers(ctx.guild!.id, { limit: 1000 });21 22 return {23 response: {24 flags: 64,25 components: [26 Container({27 accentColor: 0x1EBE38,28 components: [29 TextDisplay({ content: '# Painel Admin' }),30 TextDisplay({ content: `Servidor: **${guild.name}**` }),31 Separator({ spacing: 'small' }),32 Section({33 accessory: Button({ 34 customId: 'users', 35 label: 'Ver', 36 style: 2 37 }),38 components: [39 TextDisplay({ content: '**Usuários**' }),40 TextDisplay({ content: `${members.length} membros` })41 ]42 }),43 Section({44 accessory: Button({ 45 customId: 'channels', 46 label: 'Ver', 47 style: 2 48 }),49 components: [50 TextDisplay({ content: '**Canais**' }),51 TextDisplay({ content: 'Gerenciar canais' })52 ]53 }),54 Separator({ spacing: 'small' }),55 ActionRow({56 components: [57 Button({ customId: 'refresh', label: 'Atualizar', style: 1 }),58 Button({ customId: 'settings', label: 'Config', style: 2 })59 ]60 })61 ]62 })63 ]64 }65 };66 });67 68 flow.state('idle')69 .on.button('users', async (ctx) => {70 const members = await discord.getMembers(ctx.guild!.id, { limit: 10 });71 const list = members72 .map(m => `• ${m.user.username}`)73 .join('\n');74 75 return {76 response: {77 flags: 64,78 components: [79 Container({80 accentColor: 0x1EBE38,81 components: [82 TextDisplay({ content: '# Usuários' }),83 TextDisplay({ content: list }),84 ActionRow({85 components: [86 Button({ customId: 'back', label: 'Voltar', style: 2 })87 ]88 })89 ]90 })91 ]92 }93 };94 });95});96 97createServer({98 publicKey: process.env.DISCORD_PUBLIC_KEY!,99 token: process.env.DISCORD_TOKEN!,100 engine101}).start();Executando
bash
1# Configure o .env2DISCORD_PUBLIC_KEY=sua_public_key3DISCORD_TOKEN=seu_token4 5# Execute6npx tsx --env-file=.env src/main.ts