{"id":23670228,"url":"https://github.com/tiritibambix/cleanbot","last_synced_at":"2025-12-16T01:30:14.139Z","repository":{"id":264533625,"uuid":"893612139","full_name":"tiritibambix/cleanbot","owner":"tiritibambix","description":"Discord Bot to Purge Server Channels","archived":false,"fork":false,"pushed_at":"2025-02-06T18:13:48.000Z","size":237,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-17T12:48:46.598Z","etag":null,"topics":["bot","discord"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tiritibambix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-24T21:53:17.000Z","updated_at":"2025-02-06T18:13:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"d1cbb945-f11c-4e9f-b45b-0d705ec1ad01","html_url":"https://github.com/tiritibambix/cleanbot","commit_stats":null,"previous_names":["tiritibambix/cleanbot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiritibambix%2Fcleanbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiritibambix%2Fcleanbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiritibambix%2Fcleanbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiritibambix%2Fcleanbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiritibambix","download_url":"https://codeload.github.com/tiritibambix/cleanbot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239685790,"owners_count":19680398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","discord"],"created_at":"2024-12-29T09:32:42.778Z","updated_at":"2025-12-16T01:30:12.073Z","avatar_url":"https://github.com/tiritibambix.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Cleanbot](https://cdn.discordapp.com/app-icons/1310261454959673354/79876aac97de54fdfc9a06fbca4f32ff.png \"Cleanbot\")\n\n# Cleanbot\n\nDiscord Bot to Purge Server Channels\n\n## New Web Interface!\n\nCleanbot now comes with a beautiful web interface for easy configuration! You can now manage your bot settings through a user-friendly dashboard.\n\n### Quick Start with Docker\n\nThe easiest way to run Cleanbot is using Docker. Here's how to set it up:\n\n1. First, create a directory for your configuration:\n```bash\nmkdir -p /srv/Files/Cleanbot/config\n```\n\n2. Start the services using docker-compose:\n```bash\ndocker-compose up -d\n```\n\nThe docker-compose.yml file includes:\n- A web interface accessible on port 5392 by default (can be changed to any port of your choice)\n- A bot service that handles Discord interactions\n- Automatic restart on failure\n- Persistent configuration storage\n\nConfiguration:\n```yaml\nservices:\n  web:\n    image: tiritibambix/cleanbot-web:latest\n    ports:\n      - \"5392:8080\"  # Change \"5392\" to any port you want to use\n    volumes:\n      - /srv/Files/Cleanbot/config:/app/config\n    environment:\n      - FLASK_ENV=production\n      - TZ=Europe/Paris\n    restart: unless-stopped\n\n  bot:\n    image: tiritibambix/cleanbot:latest\n    volumes:\n      - /srv/Files/Cleanbot/config:/app/config\n    environment:\n      - TZ=Europe/Paris\n    expose:\n      - \"8081\"\n    restart: unless-stopped\n\nnetworks:\n  cleanbot_network:\n    driver: bridge\n```\n\nUsage:\n- Access the web interface at http://localhost:5392\n- Configure your Discord bot token and channel IDs\n- Set up your cleaning schedule\n- Use `docker-compose logs` to view the logs\n- Use `docker-compose down` to stop the services\n\n### Features\n\n- 🌐 Web interface for easy configuration\n- 🔄 Automatic message purging\n- ⏰ Configurable schedule (daily, weekly, monthly)\n- 🔒 Secure configuration storage\n- 🐳 Docker support\n- 🚀 Easy deployment\n\n### Configuration Options\n\nThrough the web interface, you can configure:\n- Discord Bot Token\n- Channel IDs to purge\n- Maximum messages to delete per run\n- Purge schedule (daily, weekly, monthly)\n\n### Manual Setup (Alternative)\n\nIf you prefer to run without Docker, follow these steps:\n\n#### 1. **Create a Discord Application**\n\n1. Go to the Discord Developer Portal.\n2. Click on **New Application**, give it a name, and click on **Create**.\n3. Go to the **Bot** tab and click on **Add Bot**. Confirm.\n4. Under **Token**, click on **Copy** to save the bot token (keep it private).\n\n#### 2. **Enable Necessary Intents in the Discord Portal:**\n\n1. Go to the Discord Developer Portal.\n2. Select your application (the bot).\n3. In the left menu, click on **Bot**.\n4. Under **Privileged Gateway Intents**, enable the **Message Content Intent** option.\n5. Click on **Save Changes**.\n\n#### 3. **Invite the Bot to Your Server**\n\n1. Under the **OAuth2** \u003e **URL Generator** tab, check:\n    - `bot` in **Scopes**.\n    - The necessary permissions in **Bot Permissions** (e.g., `Send Messages`).\n2. Copy the generated URL and open it in your browser.\n3. Invite the bot to your Discord server by following the instructions.\n\n#### 4. **Obtain Channel IDs**\n\nEnable **Developer Mode** in Discord (Settings \u003e Advanced \u003e Developer Mode). Right-click on the relevant channel and select **Copy ID**.\n\n#### 5. **Install Dependencies**\n\nOn your Debian, install Python and the necessary libraries:\n\n```bash\nsudo apt update\nsudo apt install python3 python3-pip -y\npip3 install discord.py\n```\n\n#### 6. **Write the Python Script**\n\nCreate a file `bot.py` with the following content:\n\n```python\nimport discord\nfrom discord.ext import commands\nimport asyncio\n\n# Replace with your own token\nTOKEN = \"YOUR_TOKEN_HERE\"\n# Replace with the IDs of the channels where you want to delete messages\nCHANNEL_IDS = [123456789012345678, 987654321098765432]  # Example channel IDs\n# Maximum number of messages to delete per execution\nAMOUNT_TO_CLEAR = 100\n\n# Initialize the bot with the necessary intents\nintents = discord.Intents.default()\nintents.messages = True  # Allows the bot to interact with messages\nintents.message_content = True  # Necessary to access message content\nbot = commands.Bot(command_prefix=\"!\", intents=intents)\n\n@bot.event\nasync def on_ready():\n    print(f\"Bot connected as {bot.user}\")\n\n    for channel_id in CHANNEL_IDS:\n        channel = bot.get_channel(channel_id)\n        if channel:\n            try:\n                # Purge messages in the channel\n                deleted = await channel.purge(limit=AMOUNT_TO_CLEAR)\n                print(f\"{len(deleted)} messages deleted in channel {channel_id}.\")\n            except discord.errors.Forbidden:\n                print(f\"Access denied to delete messages in channel {channel_id}.\")\n            except discord.errors.HTTPException as e:\n                print(f\"HTTP error while attempting to purge in channel {channel_id}: {e}\")\n        else:\n            print(f\"Channel with ID {channel_id} not found.\")\n\n    # Stop the bot after executing the purge\n    await bot.close()\n\n# Run the bot\nbot.run(TOKEN)\n```\n\n#### 7. Run the Bot in the Background with `nohup`\n\nTo run the bot in the background, you can use `nohup` so it continues to run even if you close the terminal. Here is the command to execute to start the bot and log the output to a file:\n\n```bash\nnohup python3 /path/to/bot.py \u003e /path/to/bot_output.log 2\u003e\u00261 \u0026\n```\n\nThis command runs the script in the background and redirects the output (logs and errors) to the `bot_output.log` file.\n\n#### 8. Set Up a Cron Job to Restart the Bot Every Monday at 5:00 AM\n\nTo automatically restart the bot every Monday at 5:00 AM, you need to set up a cron job. To do this, edit your crontab:\n\n```bash\ncrontab -e\n```\n\nAdd the following line to run the bot every Monday at 5:00 AM:\n\n```bash\n0 5 * * 1 nohup python3 /path/to/bot.py \u003e path/to/bot_output.log 2\u003e\u00261 \u0026\n```\n\n`nohup` is optional since the script is not being run from the terminal.\n\nThis will ensure that your bot is automatically executed every Monday at 5:00 AM.\n\n## Conclusion\n\nWith this guide, you have a Discord bot that purges messages every 7 days in the channels of your choice. You can adapt the script and settings according to your needs and use `cron` to schedule the automatic execution of the bot every Monday at 5:00 AM.\n\n---\n\n### Important Points\n\n- **Keep your token secret**: Never share your token. If you think it is compromised, regenerate it from the Discord portal.\n- **Bot permissions**: Ensure the bot has the necessary permissions on each channel.\n- **Test locally**: Make sure the script works correctly before automating it.\n\n### Docker Images\n\nOur Docker images are available on Docker Hub:\n- Bot: `tiritibambix/cleanbot:latest`\n- Web Interface: `tiritibambix/cleanbot-web:latest`\n\n### License\n\nThis project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiritibambix%2Fcleanbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiritibambix%2Fcleanbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiritibambix%2Fcleanbot/lists"}