TerrificTable55

Untitled

Apr 9th, 2022
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. from discord.ext import commands
  2. import discord
  3. import time
  4.  
  5. client = commands.Bot(command_prefix='>')
  6. users = {}
  7. channelID = None
  8. token = "" # <-- TOKEN HERE
  9.  
  10.  
  11. async def log(msg):
  12.     date = time.strftime("%d/%m/%Y | %H:%M:%S")
  13.     log_msg = f"[{date}] {msg.author} ({users[msg.author.name]}): {msg.content}"
  14.  
  15.     # log message and date in console and log file
  16.     print(log_msg)
  17.     with open(f"./bot.{time.strftime('%d-%m')}.log", "a") as f:
  18.         f.write(log_msg + "\n")
  19.  
  20.     # post message and date in log channel
  21.     if channelID:
  22.         channel = client.get_channel(int(channelID))
  23.         await channel.send(log_msg)
  24.  
  25.  
  26. @client.event
  27. async def on_ready():
  28.     print(client.user.__str__() + " Ready")
  29.  
  30.  
  31. @client.event
  32. async def on_message(msg):
  33.     if msg.author == client.user:
  34.         return
  35.     author = msg.author.name
  36.  
  37.     try:
  38.         messages = users[author] + 1
  39.     except:
  40.         messages = 1
  41.     users.update({author: messages})
  42.  
  43.     await log(msg)
  44.     await client.process_commands(msg)
  45.  
  46.  
  47. @ client.command(name='log_channel')
  48. async def log_channel(ctx, arg):
  49.     global channelID
  50.     if arg == str:
  51.         channelID = discord.utils.get(ctx.guild.channels, name=arg).id
  52.     else:
  53.         channelID = arg
  54.     print("ChannelID " + channelID)
  55.  
  56. client.run(token)
Advertisement
Add Comment
Please, Sign In to add comment