TerrificTable55

Untitled

Apr 19th, 2022
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.25 KB | None | 0 0
  1. from discord.ext import commands
  2. import time
  3.  
  4. client = commands.Bot(command_prefix='>')
  5. users = {}
  6. command_channel = "╚🤖bot-fun"
  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"[\033[90m{date}\033[0m] \033[95m{msg.author}\033[96m ({users[msg.author.name]})\033[0m: {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 or msg.author.is_system() or msg.author.bot():
  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, *args):
  49.     global channelID
  50.  
  51.     if not ctx.channel.name == (command_channel):
  52.         await ctx.reply("This command is only avalable in #" + command_channel)
  53.         return
  54.  
  55.     if not args[0].isdigit():
  56.         print("ChannelID " + args[0] + "   is invalid")
  57.         await ctx.reply(args[0] + " is not a valid channel id")
  58.         return
  59.  
  60.     channelID = args[0]
  61.  
  62.     print("ChannelID " + channelID)
  63.  
  64.  
  65. async def help_message(ctx):
  66.     await ctx.reply(f"===HELP===\n" +
  67.                     "  > list               <>          Returns a list of all users message counts\n" +
  68.                     "  > [username]         <>          Returns how many messages [username] send\n" +
  69.                     "  > help               <>          Returns this message")
  70.  
  71.  
  72. async def list_message(ctx):
  73.     res = []
  74.     for user in users:
  75.         res.append(f"{user}     {users[user]}\n")
  76.     await ctx.reply("===Message Count List===\n" +
  77.                     "User               Messages\n" +
  78.                     "".join(res) + "\n" +
  79.                     "'>messages help' for more commands")
  80.  
  81.  
  82. async def user_message_count(ctx, args):
  83.     await ctx.reply(f"==={args[0]}'s Message Count===\n" +
  84.                     f"{args[0]}     {users[args[0]]}")
  85.  
  86.  
  87. async def error_message(ctx, args):
  88.     await ctx.reply(f"User '{args[0]}' not found or hasn't send any messages yes\n" +
  89.                     f"Incase you wanted to execute a command use '>messages help' to get a list of all commands since '{args[0]}' isn't a valid command")
  90.  
  91.  
  92. @client.command(name='messages')
  93. async def messages(ctx, *args):
  94.     if not ctx.channel.name == (command_channel):
  95.         await ctx.reply("This command is only avalable in #" + command_channel)
  96.         return
  97.  
  98.     if len(args) < 1:
  99.         await list_message(ctx)
  100.  
  101.     if args[0] in users:
  102.         await user_message_count(ctx, args)
  103.  
  104.     elif args[0] == "help":
  105.         await help_message(ctx)
  106.  
  107.     elif args[0] == "list":
  108.         await list_message(ctx)
  109.  
  110.     else:
  111.         await error_message(ctx, args)
  112.  
  113. client.run(token)
Advertisement
Add Comment
Please, Sign In to add comment