Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import discord
- import os
- from datetime import datetime
- import asyncio
- from discord.ext import commands
- from replit import db
- messages = joined = 0
- intents = discord.Intents.default()
- intents.members = True
- bot = commands.Bot(command_prefix="/", intents=intents)
- TOKEN = os.environ['TOKEN']
- media_channels = ["media", "bug-reports", "memes"]
- WelcomeId = "1006898005426851880"
- WelcomeChannel = 0
- db["servers"] = []
- #####START
- with open("users.json", "ab+") as ab:
- ab.close()
- f = open('users.json','r+')
- f.readline()
- if os.stat("users.json").st_size == 0:
- f.write("{}")
- f.close()
- else:
- pass
- with open('users.json', 'r') as f:
- users = json.load(f)
- #######
- def update_settings(serverid, newdata):
- db[serverid] = newdata
- characters_to_remove = "<#>"
- async def update_stats():
- await bot.wait_until_ready()
- global messages, joined
- while not bot.is_closed():
- try:
- now = datetime.now()
- dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
- with open("stats.txt", "a") as f:
- f.write(f"Time: {dt_string}, Messages: {messages}, Members Joined: {joined}\n")
- messages = 0
- joined = 0
- await(asyncio.sleep(7200))
- except Exception as e:
- print(e)
- await(asyncio.sleep(7200))
- @bot.event
- async def on_guild_join(guild):
- print(guild)
- @bot.command()
- async def clear(ctx, info):
- async for message in ctx.channel.history(limit=int(info)):
- await message.delete()
- @bot.command()
- async def embed(ctx):
- async for message in ctx.channel.history(limit=1):
- await message.delete()
- embedVar = discord.Embed(title= "Server Rules", description= "**INAPPROPRIATE CONVERSATION**\n\n- Sex\n- Drugs/Alcohol\n \t \ Medical or educational discussion about drugs are allowed\n \t \ Promotion of drug use or distribution of drugs is not allowed.\n- Swearing is permitted if not used excessively or in a derogatory way.\n \t \ Words or phrases deemed too inappropriate will still be moderated\n- Controversial or sensitive topics (religion, political, etc)\n- Racism, sexism, transphobia, homophobia, harassment\n- Discussing any moderation actions. Please submit a ticket to discuss further.\n- Discussions of exploiting\n \t \ This applies to how to make an exploit, and how to use\n\n**PROVOKING, TARGETING, HARASSMENT**\n\n- Bullying: negatively targeting the user in direct messages, constantly pinging them with negative remarks, etc\n- Racism, sexism, trans-phobia, homophobia, harassment or threatening another user\n \t \ Provoking phobias with intent to upset or bother another user, if asked to not post something such as an image of a spider please respect their request.\n- Provoking, baiting, stimulating intense situations, or deliberately making users respond in a hostile manner is not tolerated. (including, but not limited to, arguing, exploiting rules and loopholes, and intentionally inciting moderators to take action.\n- Encouraging suicide\n\n**PLEASE NOTE:** Giving criticism is not considered any of these. However, if you're strictly targeting someone and continuously saying their work is bad without any suggested improvements is considered harassment.**", color= 0xE17B24)
- await ctx.channel.send(embed=embedVar)
- default_roles = ["1006898005426851880"]
- @bot.command()
- @commands.is_owner()
- async def reload(ctx, extension):
- bot.reload_extension(f"cogs.{extension}")
- embed = discord.Embed(title='Reload', description=f'{extension} successfully reloaded', color=0xff00c8)
- await ctx.send(embed=embed)
- @bot.command()
- async def setwelcomechannel(ctx, a):
- att = ""
- for character in characters_to_remove:
- a = a.replace(character, "")
- att = a
- print(att)
- for channel in ctx.guild.channels:
- print(str(channel.id) + " " + channel.name)
- if att == str(channel.id):
- global WelcomeId
- WelcomeId = channel.id
- await ctx.channel.send("Set welcome channel to " + channel.mention + "!")
- return
- await ctx.channel.send("That's not a valid channel!")
- @bot.event
- async def on_member_join(member):
- ##level stuff
- ##
- global joined
- joined += 1
- now = datetime.now()
- WelcomeChannel = bot.get_channel(WelcomeId)
- dt_string = now.strftime("%H:%M:%S")
- div1 = discord.utils.get(member.guild.roles, id=1006898005426851880)
- div2 = discord.utils.get(member.guild.roles, id=1006897042896978000)
- div3 = discord.utils.get(member.guild.roles, id=1006897978994331760)
- div4 = discord.utils.get(member.guild.roles, id=1006895890843304037)
- member_role = discord.utils.get(member.guild.roles, id=1007683496464093194)
- await member.add_roles(div1)
- await member.add_roles(div2)
- await member.add_roles(div3)
- await member.add_roles(div4)
- await member.add_roles(member_role)
- with open("members.txt", "a") as f:
- f.write(f"[{dt_string}]: {member.name} has just joined!\n")
- await WelcomeChannel.send("Welcome " + member.mention + "!")
- @bot.event
- async def on_message(message):
- ## Process Commands
- if not message.author == bot.user:
- with open('users.json', 'r') as f:
- users = json.load(f)
- await add_experience(users, message.author)
- await level_up(users, message.author, message)
- with open('users.json', 'w') as f:
- json.dump(users, f)
- await bot.process_commands(message)
- await bot.process_commands(message)
- Channel = message.channel
- print("")
- ##Level
- ##
- now = datetime.now()
- dt_string = now.strftime("%H:%M:%S")
- with open("message_logs/all.txt", "a") as f:
- f.write(f"[{dt_string}]: {message.author.name} - {message.content}\n")
- ## Add to Stats
- global messages
- messages += 1
- ## Media Filter
- if message.attachments:
- if not Channel in media_channels:
- await message.delete()
- ##
- ##Levels
- async def add_experience(users, user):
- if not f'{user.id}' in users:
- users[f'{user.id}'] = {}
- users[f'{user.id}']['experience'] = 0
- users[f'{user.id}']['level'] = 0
- users[f'{user.id}']['experience'] += 6
- print(f"{users[f'{user.id}']['level']}")
- async def level_up(users, user, message):
- experience = users[f'{user.id}']["experience"]
- lvl_start = users[f'{user.id}']["level"]
- lvl_end = int(experience ** (1 / 4))
- if lvl_start < lvl_end:
- await message.channel.send(f':tada: {user.mention} has reached level {lvl_end}. Congrats! :tada:')
- users[f'{user.id}']["level"] = lvl_end
- @bot.command()
- async def rank(ctx, member: discord.Member = None):
- if member == None:
- userlvl = users[f'{ctx.author.id}']['level']
- #await ctx.send(f'{ctx.author.mention} You are at level {userlvl}!')
- exp = users[f'{ctx.author.id}']["experience"]
- embed1 = discord.Embed(title = 'Level {}'.format(userlvl), description = f"{exp} XP " ,color = discord.Color.green())
- embed1.set_author(name = ctx.author, icon_url = ctx.author.avatar_url)
- await ctx.send(embed = embed1)
- else:
- userlvl2 = users[f'{member.id}']['level']
- #await ctx.send(f'{member.mention} is at level {userlvl2}!')
- exp = users[f'{member.id}']["experience"]
- embed2 = discord.Embed(title = 'Level {}'.format(userlvl2), description = f"{exp} XP " ,color = discord.Color.green())
- embed2.set_author(name = member, icon_url = member.avatar_url)
- await ctx.send(embed = embed2)
- #############
- bot.loop.create_task(update_stats())
- bot.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement