Developing Async Python Discord Bots with discord.py and 24/7 Hosting
Build modern slash command bots using discord.py 2.0+, virtual environments, and continuous daemon supervision.
Bu səhifədə
Discord Bots bələdçiləri
Modern Python Discord bot development leverages `discord.py` 2.0+ with asyncio concurrency. Using a clean virtual environment (`venv`) prevents library collisions across server workloads.
1. Modern Slash Command Template#
import os
import discord
from discord import app_commands
from discord.ext import commands
intents = discord.Intents.default()
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
await bot.tree.sync()
print(f"Bot aktif: {bot.user}")
@bot.tree.command(name="ping", description="Gecikme süresini ölçer")
async def ping(interaction: discord.Interaction):
latency = round(bot.latency * 1000)
await interaction.response.send_message(f"Pong! Gecikme: {latency}ms")
bot.run(os.getenv("DISCORD_TOKEN"))Bunu necə tətbiq etmək olar?
Clodo Control Panel Quick Method
Runtime selection in the panelThe Python runtime is selected in the panel; you do not install an OS or manage pip by hand.
Addım-addım icra:
- 1Pick the Python version on the 'Runtime' tab.
- 2Upload bot.py and requirements.txt from the 'SFTP & Files' tab.
- 3Dependencies are installed from requirements.txt on boot, so keep that file current.
- 4Start the service and follow the logs in the panel console.
Tez-tez verilən suallar
What should I do if slash commands do not appear immediately on Discord after adding them?
Make sure the await bot.tree.sync() call executes in your code. Global commands can take a brief delay to propagate across Discord servers.
What should I do when I add a new Python library to my project?
Add the package name to your requirements.txt file. When your Clodo service restarts, dependencies listed in that file are installed automatically.
What risk is there if I hardcode my bot token into the script?
Uploading your code to GitHub or sharing it can expose your token. A compromised token allows unauthorized actions on your bot, so always keep it in environment variables.
Can I use synchronous (blocking) libraries in my discord.py bot?
Long-running synchronous operations block the asyncio event loop and can cause the bot to drop its Discord connection. Use async libraries or run blocking calls in separate threads.
Bu bələdçi faydalı oldu?
Rəy birbaşa bu bələdçini yeniləyən komandaya gedir.
Həll tapa bilmədiniz?
Paneldən dəstək komandamıza müraciət aça bilərsiniz.

