Basic creation - Gllitter-bot/ilmina_bot GitHub Wiki

基本的なBOTの作り方

かなり基本的なBOTの作り方についてです。
プログラムの内容にも触れながら説明します。

必要な記述

まずは、discord上でBOTを動かすのに最低限必要な記述についてです。

import discord

client = discord.Client()

client.run('BOTのトークン')

これはdiscordというモジュールのインポートとBOTの起動を行っています。
client.runについては、 必ずプログラムの最後 に記述してください。
BOTのトークンは、Discordの開発者ページから取得することが出来ます。
詳しい方法については後述する、かもしれません。

# BOTの起動とログイン
@client.event
async def on_ready():

上記を含めたものが最も基本的なBOTのプログラムになります。

# サンプル
import discord

client = discord.Client()

@client.event
async def on_ready():
    print("ユーザー名:", client.user.name)
    print("ユーザーID:", client.user.id)

client.run('BOTのトークン')
⚠️ **GitHub.com Fallback** ⚠️