Abdullah Ahmed Ahmed
📎 1 file 7,731 chars
📄
pasted-code-1793603292230.txt
txt 252 lines
▶
# Discord GIF Restriction Bot – Complete Development Prompt

Create a fully functional, lightweight and reliable Discord bot using **JavaScript (Node.js), Discord.js v14 and PostgreSQL**.

The bot's main purpose is to completely restrict GIF usage for everyone except roles specifically allowed by server administrators, such as Server Boosters.

## 1. GIF Detection System

The bot must detect and block:

- GIFs sent through Discord's built-in GIF picker.
- Tenor GIFs.
- Giphy GIFs.
- Direct `.gif` URLs.
- Uploaded `.gif` files.
- GIFs embedded through external websites.
- GIFs from other common GIF-hosting services.

The detection system should inspect message attachments, embeds, URLs and supported media metadata.

**Important:** Do not block:
- Normal website links.
- Regular PNG, JPG and JPEG images.
- Normal video files.
- Regular Discord messages.
- Other non-GIF attachments.

Do not disable Discord's Embed Links or Attach Files permissions as a workaround.

If Discord does not expose enough information to identify a particular GIF, implement the best possible detection method and clearly document its limitations.

## 2. Role Permissions

- Members without an allowed role cannot send GIFs.
- Members with an allowed role can send GIFs normally.
- Administrators can configure multiple allowed roles.
- Administrators can configure staff bypass roles.
- Users with Administrator permission should automatically bypass restrictions.
- Role permissions must be checked dynamically.
- Removing a role from the allowed list must immediately revoke its GIF permission.

## 3. Automatic Moderation

When an unauthorized member sends a GIF:

1. Automatically delete the message.
2. Send a short warning to the member.
3. Do not timeout, kick or ban the member.
4. Prevent repeated warnings from spamming channels.
5. Log deleted GIF messages in the configured moderation log channel.
6. Include the member, channel, detected GIF source and deletion time in the log.
7. Handle missing permissions and deletion errors gracefully.

## 4. Slash Commands

Create the following slash commands:

### Main Configuration

`/gifconfig`
- Display the current server configuration.
- Show whether restrictions are enabled.
- Show allowed roles, bypass roles and restricted channels.
- Show the configured log channel.

`/gifconfig enable`
- Enable GIF restrictions.

`/gifconfig disable`
- Disable GIF restrictions.

`/gifconfig reset`
- Reset all settings to their defaults.
- Require confirmation before resetting.

### Allowed Roles

`/gifconfig allowrole add [role]`
- Allow a selected role to send GIFs.

`/gifconfig allowrole remove [role]`
- Remove a role's permission to send GIFs.

`/gifconfig allowrole list`
- Display all currently allowed roles.

### Staff Bypass

`/gifconfig bypass add [role]`
- Allow a selected staff role to bypass restrictions.

`/gifconfig bypass remove [role]`
- Remove a staff role's bypass permission.

`/gifconfig bypass list`
- Display all bypass roles.

### Channel Configuration

`/gifconfig channel add [channel]`
- Enable GIF restrictions in a specific channel.

`/gifconfig channel remove [channel]`
- Remove GIF restrictions from a specific channel.

`/gifconfig channel exempt [channel]`
- Exempt a channel from GIF restrictions.

`/gifconfig channel list`
- Display all configured channels.

### Logging

`/gifconfig logchannel [channel]`
- Set the moderation log channel.

`/gifconfig logchannel disable`
- Disable moderation logging.

### Warning Configuration

`/gifconfig warning set [message]`
- Set a custom warning message.

`/gifconfig warning reset`
- Restore the default warning message.

### GIF Source Configuration

`/gifconfig source [source] [enable/disable]`
- Enable or disable detection for supported GIF sources.

### Automatic Deletion

`/gifconfig autodelete [enable/disable]`
- Enable or disable automatic GIF deletion.

### Testing

`/gifconfig test`
- Test the GIF detection system and display its status.

## 5. Administrator Configuration

All settings must be configurable directly through Discord.

- Only users with Discord Administrator permission can modify server settings.
- Regular members cannot access configuration commands.
- Administrators can configure allowed roles, bypass roles, channels, warning messages and logging.
- Administrators can enable or disable individual features.
- Administrators can view the complete configuration.
- Configuration changes must take effect immediately.
- Every server must have independent settings.

Do not require administrators to edit source code, configuration files or PostgreSQL manually.

## 6. PostgreSQL Database

Use PostgreSQL to permanently store:

- Discord guild IDs.
- Restriction enabled/disabled status.
- Allowed role IDs.
- Bypass role IDs.
- Restricted channel IDs.
- Exempt channel IDs.
- Moderation log channel ID.
- Custom warning messages.
- GIF source settings.
- Automatic deletion settings.
- Other server-specific configurations.

Requirements:

- Automatically create database tables if they do not exist.
- Save all configuration changes immediately.
- Restore settings after bot restarts.
- Keep different servers' settings separate.
- Handle database connection errors.
- Use efficient queries and connection pooling.
- Never store sensitive credentials directly in source code.

## 7. User Experience

- Keep warning messages short and clear.
- Use clean Discord embeds for configuration responses.
- Use ephemeral responses for administrator commands where appropriate.
- Display role and channel mentions instead of raw IDs.
- Provide confirmation buttons for destructive actions.
- Display clear success and error messages.
- Prevent unauthorized users from executing administrator commands.

Example warning:

"GIFs are restricted in this server. Only members with an authorized role can send GIFs."

## 8. Technical Requirements

Use:

- JavaScript (Node.js).
- Discord.js v14.
- PostgreSQL.
- `pg` for PostgreSQL connections.
- Environment variables for credentials.
- Slash commands for all bot configuration.

The bot must:

- Support multiple Discord servers.
- Be compatible with Wispbyte hosting.
- Have proper error handling.
- Avoid unnecessary database queries.
- Handle Discord API rate limits.
- Recover database connections when possible.
- Include proper logging.
- Have a clean and organized project structure.

## 9. Wispbyte Deployment

Provide complete instructions for:

- Installing dependencies.
- Setting up PostgreSQL.
- Configuring environment variables.
- Connecting the bot to PostgreSQL.
- Registering slash commands.
- Setting the Discord bot token.
- Starting the bot on Wispbyte.
- Keeping the bot online.
- Troubleshooting common errors.

## 10. Final Deliverables

Generate:

- Complete working source code.
- `package.json`.
- Database connection file.
- Database schema and initialization.
- All slash command files.
- GIF detection system.
- Automatic moderation system.
- Configuration management system.
- `.env.example`.
- Complete Wispbyte installation instructions.

Do not provide pseudocode, incomplete functions or placeholder implementations.

Before finishing, verify that all commands work, configurations persist after restarting, role exemptions work correctly, and normal links, images and videos are not accidentally blocked.

The final result must be a production-ready Discord GIF restriction bot that administrators can completely configure from within Discord.
Kodari AI
KodariNov 2 at 7:18 am 1
GifGuardian
A Discord moderation bot that restricts GIF usage to authorized roles only. Detects and blocks GIFs from Discord picker, Tenor, Giphy, direct URLs, uploads, and embeds while allowing normal images, videos, and links. Features slash commands for configuring allowed roles, staff bypass roles, channel restrictions, custom warnings, and moderation logging. Uses PostgreSQL for persistent per-server settings, automatic message deletion, and dynamic role permission checks. Includes confirmation buttons for destructive actions and ephemeral responses for admin commands.
  1. Create the Discord.js v14 bot, PostgreSQL persistence, and GIF detection/moderation.

  2. Add administrator-only /gifconfig commands for roles, channels, warnings, sources, and logging.

  3. Add environment examples and Wispbyte setup, including detection limitations and required Discord permissions.

Created the Discord.js v14 GIF restriction bot with PostgreSQL configuration persistence, automatic table creation, and per-server settings.

  • Added administrator-only /gifconfig commands for role exemptions, channel rules, warnings, logging, source detection, auto-deletion, and reset confirmation.

  • Added GIF detection for uploads, direct GIF URLs, Tenor, Giphy, and selected GIF-hosting sites, with rate-limited warnings and moderation logs.

  • Added .env.example and README.md with Wispbyte setup, permissions, command usage, and detection limitations.

  • Slash commands register on startup; set DISCORD_GUILD_ID to register them to a test server.

Before starting, set DISCORD_TOKEN and DATABASE_URL, enable Message Content Intent in the Discord Developer Portal, and grant the bot Manage Messages, Send Messages, View Channels, and Read Message History. Some GIF-picker media is proxied or served as video, so Discord may not expose enough information to identify every GIF; this limitation is documented.

I didn’t run the bot against a live Discord server or PostgreSQL database.

Abdullah Ahmed Ahmed

can you change the banner and logo for me? i can give them both

Kodari AI
KodariNov 2 at 7:26 am 1

The generation was stopped before any content could be produced.

Abdullah Ahmed Ahmed

can you change the banner and logo for me? i can give them both

Kodari AI
KodariNov 2 at 7:27 am 1

You can send both. I can help you prepare them, but I can’t directly change your Discord bot’s branding from here—you’ll upload them in the Discord Developer Portal. If you want me to create or edit the images, enable Generation in this project’s settings under Generation.

Abdullah Ahmed Ahmed

here is the banner

Kodari AI
KodariNov 2 at 7:30 am 1

Got the banner. Send the logo too, and I’ll help you get both ready for your bot’s Discord Developer Portal profile.

Abdullah Ahmed Ahmed
Kodari AI
KodariNov 2 at 7:32 am 1

Both images are suitable to use as-is: the square image for the bot avatar, and the wide image for the banner. I can’t upload them to your Discord account, but you can set them in the Discord Developer Portal: open your application, change the avatar under Bot, and upload the banner in the app’s profile settings. Discord may crop or resize them during upload.

Abdullah Ahmed Ahmed

how can i get the bot files?

Kodari AI
KodariNov 2 at 7:33 am 1

The bot files are in this project’s file browser. Download the project files there; start with README.md for setup instructions. The main entry point is bot.js, with command and database code under src/. Copy .env.example to .env and add your Discord token and PostgreSQL connection string before starting the bot.

Abdullah Ahmed Ahmed

give me a direct link here

Abdullah Ahmed Ahmed

all in one and tell me how to setup

Kodari AI
KodariNov 2 at 7:38 am 1

Here are all the project files in one place. Keep the folder structure when downloading; I can’t provide a single ZIP link here.

Setup

  1. Create a Discord application and bot in the Discord Developer Portal. Copy the bot token.

  2. Enable Message Content Intent under Bot → Privileged Gateway Intents.

  3. Invite the bot with the bot and applications.commands scopes. Grant it View Channels, Read Message History, Send Messages, and Manage Messages. Grant Embed Links in the moderation log channel if you want embeds there.

  4. Set up PostgreSQL and get its connection URL.

  5. Set these environment variables in the project’s settings (or locally in a .env file copied from .env.example):

    • DISCORD_TOKEN — your bot token

    • DATABASE_URL — your PostgreSQL connection URL

    • Optional: DISCORD_GUILD_ID — your test server ID, for faster slash-command registration

    • Optional: PGSSLMODE=require — only if your database requires TLS

  6. Install dependencies with npm install, then start with npm start. The bot creates its database table and registers /gifconfig on startup.

  7. Use /gifconfig in your server to configure restrictions. Deploy the Discord bot project on Kodari to keep it hosted.

Don’t share your bot token or commit your .env file.

Kodari can make mistakes. Review important code before using.
Files
src
.gitignore
bot.js
package.json
README.md
Code
9 785
bot.js
require('dotenv').config();

const { Client, Events, GatewayIntentBits } = require('discord.js');
const { initializeDatabase, closeDatabase } = require('./src/database');
const { handleMessage } = require('./src/moderation');
const gifConfigCommand = require('./src/commands/gifconfig');

if (!process.env.DISCORD_TOKEN) {
    throw new Error('DISCORD_TOKEN is required. Set it in the environment or .env file.');
}

const client = new Client({
    intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});

client.once(Events.ClientReady, async (readyClient) => {
    try {
        const commands = [gifConfigCommand.command.toJSON()];
        if (process.env.DISCORD_GUILD_ID) {
            const guild = await readyClient.guilds.fetch(process.env.DISCORD_GUILD_ID);
            await guild.commands.set(commands);
            console.log(`Registered slash commands in guild ${guild.id}.`);
        } else {
            await readyClient.application.commands.set(commands);
            console.log('Registered global slash commands. Global command updates may take time to appear.');
        }
    } catch (error) {
        console.error('Slash command registration failed:', error);
    }
    console.log(`Bot is ready! Logged in as ${readyClient.user.tag}`);
    console.log('KODARI_READY');
});

client.on(Events.MessageCreate, async (message) => {
    try {
        await handleMessage(message);
    } catch (error) {
        console.error(`GIF moderation failed for guild ${message.guildId ?? 'DM'}:`, error);
    }
});

client.on(Events.InteractionCreate, async (interaction) => {
    if (!interaction.isChatInputCommand() || interaction.commandName !== 'gifconfig') return;
    try {
        await gifConfigCommand.execute(interaction);
    } catch (error) {
        console.error('GIF configuration command failed:', error);
        const response = { content: 'The command could not be completed. Check the bot logs and database connection.', ephemeral: true };
        if (interaction.deferred || interaction.replied) {
            await interaction.followUp(response).catch(() => {});
        } else {
            await interaction.reply(response).catch(() => {});
        }
    }
});

client.on(Events.Error, (error) => console.error('Discord client error:', error));
process.on('unhandledRejection', (error) => console.error('Unhandled promise rejection:', error));

async function shutdown(signal) {
    console.log(`Received ${signal}; shutting down.`);
    client.destroy();
    try {
        await closeDatabase();
    } catch (error) {
        console.error('Error closing PostgreSQL pool:', error);
    }
    process.exit(0);
}

process.once('SIGINT', () => shutdown('SIGINT'));
process.once('SIGTERM', () => shutdown('SIGTERM'));

async function start() {
    try {
        await initializeDatabase();
        console.log('PostgreSQL connection established and schema is ready.');
        await client.login(process.env.DISCORD_TOKEN);
    } catch (error) {
        console.error('Bot startup failed:', error);
        await closeDatabase().catch(() => {});
        process.exitCode = 1;
    }
}

start();