Hosting Bota Discord (Node.js / Python)
LeafHost pozwala na uruchamianie botów Discord działających 24/7 w środowiskach Node.js oraz Python.
Wymagane Pliki dla Bota Node.js
Upewnij się, że Twój projekt zawiera prawidłowy plik package.json ze wskazanym plikiem wykonywalnym:
package.json
{
"name": "leafhost-discord-bot",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"discord.js": "^14.14.0",
"dotenv": "^16.4.0"
}
}
Przykładowy Kod Bota (index.js):
index.js
const { Client, GatewayIntentBits } = require('discord.js');
require('dotenv').config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
]
});
client.once('ready', () => {
console.log(`[LeafHost Bot] Zalogowano jako ${client.user.tag}!`);
});
client.on('messageCreate', (message) => {
if (message.content === '!ping') {
message.reply('Pong! Serwer LeafHost działa prawidłowo.');
}
});
client.login(process.env.DISCORD_TOKEN);
Wymagane Pliki dla Bota Python
Dla botów pisanych w Pythonie utwórz plik requirements.txt:
requirements.txt
discord.py>=2.3.0
python-dotenv>=1.0.0
main.py
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'[LeafHost Bot] Zalogowano jako {bot.user}')
@bot.command()
async def ping(ctx):
await ctx.send('Pong from LeafHost server!')
bot.run(os.getenv('DISCORD_TOKEN'))
:::caution Kluczowe Bezpieczeństwo Tokenu
Nigdy nie wklejaj swojego Tokenu Bota bezpośrednio w kodzie! Używaj pliku .env i dodaj .env do pliku .gitignore.
:::