Update bot.py

This commit is contained in:
ElBe 2022-10-14 18:03:04 +02:00 committed by GitHub
parent 123db972a5
commit 74e795c91b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,8 @@
''' '''
Bot from The Guardians. Discord bot template.
© by ElBe. © by ElBe.
Version: 0.1.7 Version: 0.1.8
''' '''
#Imports #Imports
@ -19,7 +19,7 @@ import psutil
import functions import functions
#Start #Start
print('Discord.py The Guardians Bot') print('Discord.py Bot')
print('----------------------------') print('----------------------------')
print('© by ElBe 2022.') print('© by ElBe 2022.')
print('') print('')
@ -45,6 +45,9 @@ starttime = time.time()
token = functions.json_module.get_config('Config')['Token'] token = functions.json_module.get_config('Config')['Token']
version = functions.json_module.get_config('Config')['Version'] version = functions.json_module.get_config('Config')['Version']
credits = functions.json_module.get_config('Config')['Credits'] credits = functions.json_module.get_config('Config')['Credits']
footer = functions.json_module.get_config('Config')['footer']
welcomeChannel = functions.json_module.get_config('Channels')['Welcome']
goodbyeChannel = functions.json_module.get_config('Channels')['Goodbye']
icon = functions.json_module.get_config('Images')['Logo'] icon = functions.json_module.get_config('Images')['Logo']
commands = functions.json_module.get_config('Commands') commands = functions.json_module.get_config('Commands')
@ -53,7 +56,7 @@ logging.basicConfig(filename='log.txt', level=logging.INFO)
intents = discord.Intents.all() intents = discord.Intents.all()
#Main #Main
class TheGuardiansBot(discord.Client): class Bot(discord.Client):
'''Bot.''' '''Bot.'''
async def on_connect(self): async def on_connect(self):
@ -70,8 +73,6 @@ class TheGuardiansBot(discord.Client):
while True: while True:
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f'/help for help.')) await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f'/help for help.'))
await asyncio.sleep(10) await asyncio.sleep(10)
await client.change_presence(activity=discord.Game(name=' with The Guardians on 6b6t.'))
await asyncio.sleep(10)
await client.change_presence(activity=discord.Game(name=f'Version {version}')) await client.change_presence(activity=discord.Game(name=f'Version {version}'))
await asyncio.sleep(10) await asyncio.sleep(10)
if credits: if credits:
@ -96,7 +97,7 @@ class TheGuardiansBot(discord.Client):
pingEmbed = discord.Embed(title='Ping', description='Ping of the bot in ms.') pingEmbed = discord.Embed(title='Ping', description='Ping of the bot in ms.')
pingEmbed.add_field(name='Latency: ', value=str(round(client.latency * 1000)) + ' ms', inline=False) pingEmbed.add_field(name='Latency: ', value=str(round(client.latency * 1000)) + ' ms', inline=False)
pingEmbed.set_thumbnail(url=client.user.avatar.url) pingEmbed.set_thumbnail(url=client.user.avatar.url)
pingEmbed.set_footer(text='Bot made by ElBe for The Guardians.') pingEmbed.set_footer(text=footer)
await interaction.response.send_message(embed=pingEmbed, ephemeral=True) await interaction.response.send_message(embed=pingEmbed, ephemeral=True)
if command_name == 'info': if command_name == 'info':
@ -105,7 +106,7 @@ class TheGuardiansBot(discord.Client):
infoEmbed.add_field(name='CPU usage: ', value=str(psutil.cpu_percent(2)) + '%', inline=False) infoEmbed.add_field(name='CPU usage: ', value=str(psutil.cpu_percent(2)) + '%', inline=False)
infoEmbed.add_field(name='Uptime: ', value=str(datetime.timedelta(seconds=int(round(time.time()-starttime)))), inline=False) infoEmbed.add_field(name='Uptime: ', value=str(datetime.timedelta(seconds=int(round(time.time()-starttime)))), inline=False)
infoEmbed.set_thumbnail(url=client.user.avatar.url) infoEmbed.set_thumbnail(url=client.user.avatar.url)
infoEmbed.set_footer(text='Bot made by ElBe for The Guardians.') infoEmbed.set_footer(text=footer)
await interaction.response.send_message(embed=infoEmbed, ephemeral=True) await interaction.response.send_message(embed=infoEmbed, ephemeral=True)
if command_name == 'stop': if command_name == 'stop':
@ -122,7 +123,7 @@ class TheGuardiansBot(discord.Client):
helpEmbed.add_field(name='Unban', value='Unbans a member from the server.', inline=True) helpEmbed.add_field(name='Unban', value='Unbans a member from the server.', inline=True)
helpEmbed.add_field(name='more', value='For more help write a direct message to <@!745695237380243457>.', inline=False) helpEmbed.add_field(name='more', value='For more help write a direct message to <@!745695237380243457>.', inline=False)
helpEmbed.set_thumbnail(url=client.user.avatar.url) helpEmbed.set_thumbnail(url=client.user.avatar.url)
helpEmbed.set_footer(text='Bot made by ElBe for The Guardians.') helpEmbed.set_footer(text=footer)
await interaction.response.send_message(embed=helpEmbed, ephemeral=True) await interaction.response.send_message(embed=helpEmbed, ephemeral=True)
if command_name == 'kick': if command_name == 'kick':
@ -137,12 +138,12 @@ class TheGuardiansBot(discord.Client):
kickEmbed = discord.Embed(title='Kick', description='Succesfully kicked <@!' + options[0]['value'] + '>!') kickEmbed = discord.Embed(title='Kick', description='Succesfully kicked <@!' + options[0]['value'] + '>!')
kickEmbed.set_thumbnail(url=client.user.avatar.url) kickEmbed.set_thumbnail(url=client.user.avatar.url)
kickEmbed.set_footer(text='Bot made by ElBe for The Guardians.') kickEmbed.set_footer(text=footer)
await interaction.response.send_message(embed=kickEmbed, ephemeral=True) await interaction.response.send_message(embed=kickEmbed, ephemeral=True)
else: else:
noPermissionsEmbed = discord.Embed(title='Missing permissions', description='You don\'t have permissions to do that.', color=discord.Color.red()) noPermissionsEmbed = discord.Embed(title='Missing permissions', description='You don\'t have permissions to do that.', color=discord.Color.red())
noPermissionsEmbed.set_thumbnail(url=client.user.avatar.url) noPermissionsEmbed.set_thumbnail(url=client.user.avatar.url)
noPermissionsEmbed.set_footer(text='Bot made by ElBe for The Guardians.') noPermissionsEmbed.set_footer(text=footer)
await interaction.response.send_message(embed=noPermissionsEmbed, ephemeral=True) await interaction.response.send_message(embed=noPermissionsEmbed, ephemeral=True)
if command_name == 'ban': if command_name == 'ban':
@ -157,12 +158,12 @@ class TheGuardiansBot(discord.Client):
banEmbed = discord.Embed(title='Ban', description='Succesfully banned <@!' + options[0]['value'] + '>!') banEmbed = discord.Embed(title='Ban', description='Succesfully banned <@!' + options[0]['value'] + '>!')
banEmbed.set_thumbnail(url=client.user.avatar.url) banEmbed.set_thumbnail(url=client.user.avatar.url)
banEmbed.set_footer(text='Bot made by ElBe for The Guardians.') banEmbed.set_footer(text=footer)
await interaction.response.send_message(embed=banEmbed, ephemeral=True) await interaction.response.send_message(embed=banEmbed, ephemeral=True)
else: else:
noPermissionsEmbed = discord.Embed(title='Missing permissions', description='You don\'t have permissions to do that.', color=discord.Color.red()) noPermissionsEmbed = discord.Embed(title='Missing permissions', description='You don\'t have permissions to do that.', color=discord.Color.red())
noPermissionsEmbed.set_thumbnail(url=client.user.avatar.url) noPermissionsEmbed.set_thumbnail(url=client.user.avatar.url)
noPermissionsEmbed.set_footer(text='Bot made by ElBe for The Guardians.') noPermissionsEmbed.set_footer(text=footer)
await interaction.response.send_message(embed=noPermissionsEmbed, ephemeral=True) await interaction.response.send_message(embed=noPermissionsEmbed, ephemeral=True)
if command_name == 'unban': if command_name == 'unban':
@ -177,12 +178,12 @@ class TheGuardiansBot(discord.Client):
unbanEmbed = discord.Embed(title='Unban', description='Succesfully unbanned <@!' + options[0]['value'] + '>!') unbanEmbed = discord.Embed(title='Unban', description='Succesfully unbanned <@!' + options[0]['value'] + '>!')
unbanEmbed.set_thumbnail(url=client.user.avatar.url) unbanEmbed.set_thumbnail(url=client.user.avatar.url)
unbanEmbed.set_footer(text='Bot made by ElBe for The Guardians.') unbanEmbed.set_footer(text=footer)
await interaction.response.send_message(embed=unbanEmbed, ephemeral=True) await interaction.response.send_message(embed=unbanEmbed, ephemeral=True)
else: else:
noPermissionsEmbed = discord.Embed(title='Missing permissions', description='You don\'t have permissions to do that.', color=discord.Color.red()) noPermissionsEmbed = discord.Embed(title='Missing permissions', description='You don\'t have permissions to do that.', color=discord.Color.red())
noPermissionsEmbed.set_thumbnail(url=client.user.avatar.url) noPermissionsEmbed.set_thumbnail(url=client.user.avatar.url)
noPermissionsEmbed.set_footer(text='Bot made by ElBe for The Guardians.') noPermissionsEmbed.set_footer(text=footer)
await interaction.response.send_message(embed=noPermissionsEmbed, ephemeral=True) await interaction.response.send_message(embed=noPermissionsEmbed, ephemeral=True)
async def on_member_join(self, member): async def on_member_join(self, member):
@ -192,10 +193,10 @@ class TheGuardiansBot(discord.Client):
print(functions.console.log(str(text))) print(functions.console.log(str(text)))
if not member == client.user: if not member == client.user:
channel = discord.utils.get(member.guild.text_channels, name='hi') channel = discord.utils.get(member.guild.text_channels, name=welcomeChannel)
joinEmbed = discord.Embed(title='Welcome!', description='Hello <@!' + str(member.id) + f'>! \nThank you for joining {member.guild.name}!') joinEmbed = discord.Embed(title='Welcome!', description='Hello <@!' + str(member.id) + f'>! \nThank you for joining {member.guild.name}!')
joinEmbed.set_thumbnail(url=member.avatar.url) joinEmbed.set_thumbnail(url=member.avatar.url)
joinEmbed.set_footer(text='Bot made by ElBe for The Guardians.') joinEmbed.set_footer(text=footer)
await channel.send(embed=joinEmbed) await channel.send(embed=joinEmbed)
await member.add_roles(discord.utils.get(member.guild.roles, name='member')) await member.add_roles(discord.utils.get(member.guild.roles, name='member'))
await log('@' + str(member) + ' joined to ' + str(member.guild.name) + '.') await log('@' + str(member) + ' joined to ' + str(member.guild.name) + '.')
@ -207,10 +208,10 @@ class TheGuardiansBot(discord.Client):
print(functions.console.log(str(text))) print(functions.console.log(str(text)))
if not member == client.user: if not member == client.user:
channel = discord.utils.get(member.guild.text_channels, name='bye') channel = discord.utils.get(member.guild.text_channels, name=goodbyeChannel)
leaveEmbed = discord.Embed(title='Goodbye!', description='<@!' + str(member.id) + f'> left {member.guild.name}.') leaveEmbed = discord.Embed(title='Goodbye!', description='<@!' + str(member.id) + f'> left {member.guild.name}.')
leaveEmbed.set_thumbnail(url=member.avatar.url) leaveEmbed.set_thumbnail(url=member.avatar.url)
leaveEmbed.set_footer(text='Bot made by ElBe for The Guardians.') leaveEmbed.set_footer(text=footer)
await channel.send(embed=leaveEmbed) await channel.send(embed=leaveEmbed)
await log('@' + str(member) + ' left ' + str(member.guild.name) + '.') await log('@' + str(member) + ' left ' + str(member.guild.name) + '.')
@ -223,5 +224,5 @@ class TheGuardiansBot(discord.Client):
await error('Bot disconected from discord.') await error('Bot disconected from discord.')
#Run #Run
client = TheGuardiansBot(intents = intents, max_messages=None) client = Bot(intents = intents, max_messages=None)
client.run(token, log_handler=None) client.run(token, log_handler=None)