Official Python SDK for KOREANBOTS
discord.py의 tasks를 이용해 서버 수를 1시간마다 자동으로 업데이트하는 예제입니다.
import discord
from discord.ext import commands, tasks
from koreanbots.client import Koreanbots
BOT_TOKEN = "your_discord_bot_token"
KOREANBOTS_API_KEY = "your_koreanbots_api_key"
bot = commands.Bot(command_prefix="!", intents=discord.Intents.default())
koreanbots = Koreanbots(KOREANBOTS_API_KEY)
@tasks.loop(hours=1)
async def update_server_count():
await koreanbots.update_bot_info(
bot_id=bot.user.id,
servers=len(bot.guilds),
shards=bot.shard_count or 0,
)
@update_server_count.before_loop
async def before_update_server_count():
await bot.wait_until_ready()
@bot.event
async def on_ready():
update_server_count.start()
print(f"Logged in as {bot.user}")
bot.run(BOT_TOKEN)