Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from discord.ext import commands
- import time
- client = commands.Bot(command_prefix='>')
- users = {}
- command_channel = "╚🤖bot-fun"
- channelID = None
- token = "" # <-- TOKEN HERE
- async def log(msg):
- date = time.strftime("%d/%m/%Y | %H:%M:%S")
- log_msg = f"[\033[90m{date}\033[0m] \033[95m{msg.author}\033[96m ({users[msg.author.name]})\033[0m: {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 or msg.author.is_system() or msg.author.bot():
- 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, *args):
- global channelID
- if not ctx.channel.name == (command_channel):
- await ctx.reply("This command is only avalable in #" + command_channel)
- return
- if not args[0].isdigit():
- print("ChannelID " + args[0] + " is invalid")
- await ctx.reply(args[0] + " is not a valid channel id")
- return
- channelID = args[0]
- print("ChannelID " + channelID)
- async def help_message(ctx):
- await ctx.reply(f"===HELP===\n" +
- " > list <> Returns a list of all users message counts\n" +
- " > [username] <> Returns how many messages [username] send\n" +
- " > help <> Returns this message")
- async def list_message(ctx):
- res = []
- for user in users:
- res.append(f"{user} {users[user]}\n")
- await ctx.reply("===Message Count List===\n" +
- "User Messages\n" +
- "".join(res) + "\n" +
- "'>messages help' for more commands")
- async def user_message_count(ctx, args):
- await ctx.reply(f"==={args[0]}'s Message Count===\n" +
- f"{args[0]} {users[args[0]]}")
- async def error_message(ctx, args):
- await ctx.reply(f"User '{args[0]}' not found or hasn't send any messages yes\n" +
- 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")
- @client.command(name='messages')
- async def messages(ctx, *args):
- if not ctx.channel.name == (command_channel):
- await ctx.reply("This command is only avalable in #" + command_channel)
- return
- if len(args) < 1:
- await list_message(ctx)
- if args[0] in users:
- await user_message_count(ctx, args)
- elif args[0] == "help":
- await help_message(ctx)
- elif args[0] == "list":
- await list_message(ctx)
- else:
- await error_message(ctx, args)
- client.run(token)
Advertisement
Add Comment
Please, Sign In to add comment