不和.Py - no 02ではなく、通常のログボット最初の部分!


こんにちは、今日、我々はテキストファイルのどんなサーバーのメッセージも記録する不活発なロボットを作成するつもりです.
さらに行く前に、最初の部分を読んでください.


暗号


コードはいつものように簡単です.
いつものように不調和をインポートして起動しましょう.Pyモジュールとクライアント( BOT )の定義
#No need to explain this piece of code just read the first part.
import discord
from discord.ext import commands


client = commands.Bot(command_prefix="!")

@client.event
async def on_ready():
    print("started")

次に、OnNoneメッセージイベントを使用します.
このイベントは、ボットが使用しているすべてのサーバーで送信されたメッセージを聞き、コードを実行します.

@client.event
async def on_message(message):
    if message == "":
        return
    else:
        id = str(message.author)
        #Sorts the message time of creation
        # %d : day of the month (01 to 31)
        # %m : month
        # %Y : year including the century
        # %H : Hour (00 to 23)
        # %M : minute
        # %S : second 

        time = str(message.created_at.strftime("%d-%m-%Y %H:%M:%S"))
        mss = str(message.content)
        #Opening the file in appending mode.
        data = open("data.txt","a")
        #writing the message into the file 
        data.write(f"({time}) {id} : {mss}\n")
#Don't forget to run the bot
client.run("Your Token")
あなたはhereでフルコードを見つけることができます

コードのテスト




読書ありがとうございます、次の部分であなたに会ってください.