不和.Py - no 02ではなく、通常のログボット最初の部分!
5397 ワード
こんにちは、今日、我々はテキストファイルのどんなサーバーのメッセージも記録する不活発なロボットを作成するつもりです.
さらに行く前に、最初の部分を読んでください.
コードはいつものように簡単です.
いつものように不調和をインポートして起動しましょう.Pyモジュールとクライアント( BOT )の定義
このイベントは、ボットが使用しているすべてのサーバーで送信されたメッセージを聞き、コードを実行します.
読書ありがとうございます、次の部分であなたに会ってください.
さらに行く前に、最初の部分を読んでください.
不和.Py 0.01
ハムザハム・ Mar 19・ 2分読む
#discord
#python
#programming
#tutorial
暗号
コードはいつものように簡単です.
いつものように不調和をインポートして起動しましょう.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でフルコードを見つけることができますコードのテスト
読書ありがとうございます、次の部分であなたに会ってください.
Reference
この問題について(不和.Py - no 02ではなく、通常のログボット最初の部分!), 我々は、より多くの情報をここで見つけました https://dev.to/oxy_oxide/discordpy-02-not-that-usual-log-bot-the-first-part-16a9テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol