Skip to content

Instantly share code, notes, and snippets.

@dpy-manager-bot
Created October 26, 2020 21:21
Show Gist options
  • Save dpy-manager-bot/2879737b89d4cf258fc34b83206baa51 to your computer and use it in GitHub Desktop.
Save dpy-manager-bot/2879737b89d4cf258fc34b83206baa51 to your computer and use it in GitHub Desktop.
A file by Copy💎#3588 in the discord.py guild
```python
# TODO fix hola to pick random string from frases.
# TODO work on timer and other functions****
import discord
import random
import time
from discord.ext import commands, tasks
from discord.utils import get
from itertools import cycle
token = ''
invite_link = 'https://discord.com/oauth2/authorize?client_id=770346084001906709&permissions=8&scope=bot'
console_line = '______________________________________________'
localtime = time.asctime(time.localtime(time.time()))
twitch_link = 'https://www.twitch.tv/werogg_'
bot = commands.Bot(command_prefix = '~')
status = cycle(['~commands para lista de commandos', 'Bienvenidos!'])
@bot.event
async def on_ready():
print('logged in as {0.user}'.format(bot))
print('Bot is online.')
print(console_line)
change_status.start()
@tasks.loop(seconds=10)
async def change_status():
await bot.change_presence(activity=discord.Game(next(status)))
# Example embed
@bot.command(pass_context=True)
async def embed(ctx):
# await ctx.send('')
channel = ctx.message.channel
embed = discord.Embed(
title='',
description='',
colour=discord.Colour.dark_purple()
)
embed.set_footer(text='')
embed.set_image(url='')
embed.set_author(name='', icon_url='')
embed.add_field(name='**Commands** \n`~commands`', value='Lista de commands.', inline=True)
# You can add more fields
await ctx.message.channel.send(embed=embed)
# TODO **Make a list from commands for admins**
# Make a system that checks for admin role, if not then don't give commands or let them use commands
# Commands list
@bot.command()
async def commands(ctx):
channel = ctx.message.channel
user = ctx.message.author
command_name = 'commands'
embed = discord.Embed(
title='Commands',
description='Lista de commands para miembros',
colour = discord.Colour.gold()
)
embed.set_footer(text='')
embed.set_author(name='â™ AceNation BOT', icon_url='')
embed.add_field(name='~hola', value='â™ AceNation BOT te dice hola.', inline=True)
embed.add_field(name='~coinflip', value='â™ AceNation BOT tira moneda para bolado', inline=True)
embed.add_field(name='~invite', value='Envia link para invitar al bot', inline=True)
embed.add_field(name='~twitch', value='Envia link de Twitch', inline=True)
embed.add_field(name='~ping', value='Manda latency con servidores de Discord', inline=True)
embed.add_field(name='~timer `#segundos`', value='Pone tiempo y manda mensaje cuando se agota', inline=True)
embed.add_field(name='~hola', value='â™ AceNation BOT te dice hola.', inline=True)
await ctx.message.channel.send(embed=embed)
print(f'{command_name} command used by {user} in {channel}')
print(console_line)
# Member Join and Leave events
@bot.event
async def on_member_join(member):
print(f'{member} joined a server.')
@bot.event
async def on_member_remove(member):
print(f'{member} left a server.')
# Hola
@bot.command()
async def hola(ctx):
# await ctx.send(f'Hola {user}!')
channel = ctx.message.channel
user_name = ctx.message.author.name
frases = [f'Hola {user_name}', f'Que tal {user_name}!']
embed = discord.Embed(
description=(random.choice(frases)),
colour=discord.Colour.gold()
)
await ctx.message.channel.send(embed=embed)
print(f'hola used in {channel}')
# Bot Invite Link
@bot.command()
async def invite(ctx):
channel = ctx.message.channel
embed = discord.Embed(
title=('Invitame a tu servidor:'),
description=(f'Invite: {invite_link}'),
colour= discord.Colour.orange()
)
await ctx.message.channel.send(embed=embed)
#Twitch Link
@bot.command()
async def twitch(ctx):
command_name = 'twitch'
user = ctx.message.author
channel = ctx.message.channel
#Send link to chat
embed = discord.Embed(
title=('Canal de Twitch:'),
description=(f'{twitch_link}'),
colour=discord.Colour.gold()
)
await ctx.message.channel.send(embed=embed)
print(f'{command_name} used in {channel} by {user}')
# Coinflip
@bot.command()
async def coinflip(ctx):
user = ctx.message.author
channel = ctx.message.channel
command_name = "coinflip"
random_number = random.randrange(1,3)
if random_number ==1:
await ctx.send('Tails!')
else:
await ctx.send('Heads!')
print(f'{command_name} command was used by {user} in {channel}')
print(console_line)
# ADMIN only commands (Start)
# Ping
@bot.command()
async def ping(ctx):
role = discord.utils.get(ctx.guild.roles, name = 'KINGS')
user = ctx.message.author
command_name = 'ping'
channel = ctx.message.channel
# await ctx.send(f' pong! `{round(bot.latency * 1000)}ms` of Latency.')
if(not role in user.roles):
print(f'{user} denied access to {command_name} command in {channel}')
print(console_line)
else:
embed = discord.Embed(
title='Ping con servidores de Discord:',
description=(f' pong! `{round(bot.latency * 1000)}ms` of Latency.'),
colour=discord.Colour.orange()
)
await ctx.message.channel.send(embed=embed)
print(f'{user} has ADMIN permission')
print(f'{command_name} command used in {channel}')
print(console_line)
# Timer
@bot.command()
async def timer(ctx, time_set):
user = ctx.message.author
channel = ctx.message.channel
command_name = 'timer'
seconds = int(time_set)
role = discord.utils.get(ctx.guild.roles, name = 'KINGS')
if(not role in user.roles):
print(f'{user} denied access to {command_name} command in {channel}')
print(console_line)
else:
if(seconds < 1):
#print(f'ERROR: {seconds} are less than one, cannot set timer.')
embed = discord.Embed(
description=(f'ERROR: {seconds} es menos de 1.'),
colour=discord.Colour.gold()
)
await ctx.message.channel.send(embed=embed)
else:
embed = discord.Embed(
title='Timer:',
description=(f'Tiempo puesto para {seconds} segundos.'),
colour=discord.Colour.gold()
)
await ctx.message.channel.send(embed=embed)
# Use timer
time.sleep(seconds)
#Alert when time done
embed = discord.Embed(
description=('Tiempo se ha agotado.'),
colour=discord.Colour.gold()
)
await ctx.message.channel.send(embed=embed)
print(f'{user} has ADMIN permission')
print(f'{command_name} command used in {channel} by {user}')
print(console_line)
# Say
@bot.command()
async def say(ctx, input_string):
channel = ctx.message.channel
user = ctx.message.author
channel = ctx.message.channel
role = discord.utils.get(ctx.guild.roles, name='ADMIN')
command_name = 'say'
#check roles
if(not role in user.roles):
print(f'{user} not not granted access to {command_name} in {channel}')
else:
input_message = str(input_string)
if(input_message.__contains__('Example1' or 'Example2')):
print(f'Message containing {input_message} was canceled in {channel}')
print(console_line)
else:
ctx.send(f'{input_message}')
# Clear
@bot.command()
async def clear(ctx, amount = 5):
role = discord.utils.get(ctx.guild.roles, name = 'KINGS')
channel = ctx.message.channel
user = ctx.message.author
command_name = 'clear'
if(not role in user.roles):
print(f'{user} tried using {command_name} in {channel}')
print(f'Reason: KINGS not found in roles.')
print(console_line)
else:
await ctx.channel.purge(limit=amount)
embed = discord.Embed(
title='Borrar:',
description=(f'Cleared `{amount}` messages from the channel.'),
colour=discord.Colour.gold()
)
await ctx.message.channel.send(embed=embed)
print(f'{user} used {command_name} in {channel} at {localtime}')
print(console_line)
@bot.command()
async def kick(ctx, member=discord.Member, *, reason=None):
role = discord.utils.get(ctx.guild.roles, name='KINGS')
user = ctx.message.author
channel = ctx.message.channel
command_name = 'kick'
if(not role in user.roles):
print(f'{user} tried using {command_name} in {channel} at {localtime}')
else:
await member.kick(reason=reason)
embed - discord.Embed(
description=(f'{member} ha sido expulsado por: {reason}'),
colour = discord.colour.gold()
)
await ctx.message.channel.send(embed=embed)
print(f'{user} used {command_name} in {channel}')
print(console_line)
@bot.command()
async def ban(ctx, member=discord.Member, *, reason=None):
role = discord.utils.get(ctx.guild.roles, name='ADMIN')
user = ctx.message.author
channel = ctx.message.channel
command_name = 'kick'
if(not role in user.roles):
print(f'{user} tried using {command_name} in {channel} at {localtime}')
else:
await member.ban(reason=reason)
embed - discord.Embed(
description=(f'{member} ha sido expulsado y baneado por: {reason}'),
colour = discord.colour.gold()
)
await ctx.message.channel.send(embed=embed)
print(f'{user} used {command_name} in {channel}')
print(console_line)
# Check for ADMIN testing
@bot.command()
async def checkadmin(ctx):
role = discord.utils.get(ctx.guild.roles, name='KINGS')
user = ctx.message.author
if(not role in user.roles):
# Test
await ctx.send('No eres Admin.')
print('Do not do command')
else:
#Test
await ctx.send('Si eres Admin.')
print('Do command')
bot.run(token)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment