Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from discord.ext import commands
- import discord
- import time
- client = commands.Bot(command_prefix='>')
- users = {}
- channelID = None
- token = "" # <-- TOKEN HERE
- async def log(msg):
- date = time.strftime("%d/%m/%Y | %H:%M:%S")
- log_msg = f"[{date}] {msg.author} ({users[msg.author.name]}): {msg.content}"
- # log message and date in console and log file
- print(log_msg)
- with open(f"./bot.{time.strftime('%d-%m')}.log", "a") as f:
- f.write(log_msg + "\n")
- # post message and date in log channel
- if channelID:
- channel = client.get_channel(int(channelID))
- await channel.send(log_msg)
- @client.event
- async def on_ready():
- print(client.user.__str__() + " Ready")
- @client.event
- async def on_message(msg):
- if msg.author == client.user:
- return
- author = msg.author.name
- try:
- messages = users[author] + 1
- except:
- messages = 1
- users.update({author: messages})
- await log(msg)
- await client.process_commands(msg)
- @ client.command(name='log_channel')
- async def log_channel(ctx, arg):
- global channelID
- if arg == str:
- channelID = discord.utils.get(ctx.guild.channels, name=arg).id
- else:
- channelID = arg
- print("ChannelID " + channelID)
- client.run(token)
Advertisement
Add Comment
Please, Sign In to add comment