Skip to content

Instantly share code, notes, and snippets.

@fazt
Created April 19, 2019 15:06
Show Gist options
  • Save fazt/e17ea3fde6988f7215301b888ccaaf5c to your computer and use it in GitHub Desktop.
Save fazt/e17ea3fde6988f7215301b888ccaaf5c to your computer and use it in GitHub Desktop.
Python Simple Discord Bot
import discord
from discord.ext import commands
import datetime
from urllib import parse, request
import re
bot = commands.Bot(command_prefix='>', description="This is a Helper Bot")
@bot.command()
async def ping(ctx):
await ctx.send('pong')
@bot.command()
async def sum(ctx, numOne: int, numTwo: int):
await ctx.send(numOne + numTwo)
@bot.command()
async def info(ctx):
embed = discord.Embed(title=f"{ctx.guild.name}", description="Lorem Ipsum asdasd", timestamp=datetime.datetime.utcnow(), color=discord.Color.blue())
embed.add_field(name="Server created at", value=f"{ctx.guild.created_at}")
embed.add_field(name="Server Owner", value=f"{ctx.guild.owner}")
embed.add_field(name="Server Region", value=f"{ctx.guild.region}")
embed.add_field(name="Server ID", value=f"{ctx.guild.id}")
# embed.set_thumbnail(url=f"{ctx.guild.icon}")
embed.set_thumbnail(url="https://pluralsight.imgix.net/paths/python-7be70baaac.png")
await ctx.send(embed=embed)
@bot.command()
async def youtube(ctx, *, search):
query_string = parse.urlencode({'search_query': search})
html_content = request.urlopen('http://www.youtube.com/results?' + query_string)
# print(html_content.read().decode())
search_results = re.findall('href=\"\\/watch\\?v=(.{11})', html_content.read().decode())
print(search_results)
# I will put just the first result, you can loop the response to show more results
await ctx.send('https://www.youtube.com/watch?v=' + search_results[0])
# Events
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Streaming(name="Tutorials", url="http://www.twitch.tv/accountname"))
print('My Ready is Body')
@bot.listen()
async def on_message(message):
if "tutorial" in message.content.lower():
# in this case don't respond with the word "Tutorial" or you will call the on_message event recursively
await message.channel.send('This is that you want http://youtube.com/fazttech')
await bot.process_commands(message)
bot.run('token')
@kaiihannam1
Copy link

what command do you need to enter to use the embed?

@kero3009destiny
Copy link

this bot wont work without token, please send your token.

@StevenDevy
Copy link

this bot wont work without token, please send your token.

What?? Are you idiot?

@kero3009destiny
Copy link

this bot wont work without token, please send your token.

What?? Are you idiot?

bro why are you mean, the bot wont work without token, please give the token so i can run the bot.

@varchasvkhare
Copy link

this bot wont work without token, please send your token.

What?? Are you idiot?

bro why are you mean, the bot wont work without token, please give the token so i can run the bot.

U r really an idiot why would anyone share the token

@kero3009destiny
Copy link

this bot wont work without token, please send your token.

What?? Are you idiot?

bro why are you mean, the bot wont work without token, please give the token so i can run the bot.

U r really an idiot why would anyone share the token

Duh, the bot wouldn't work without the token, that's why.

@vyishere
Copy link

this bot wont work without token, please send your token.

What?? Are you idiot?

bro why are you mean, the bot wont work without token, please give the token so i can run the bot.

U r really an idiot why would anyone share the token

Duh, the bot wouldn't work without the token, that's why.

Create a bot then use your own token.

@kero3009destiny
Copy link

this bot wont work without token, please send your token.

What?? Are you idiot?

bro why are you mean, the bot wont work without token, please give the token so i can run the bot.

U r really an idiot why would anyone share the token

Duh, the bot wouldn't work without the token, that's why.

Create a bot then use your own token.

Pretty sure that's a ploy to get me to use your token logger 😐

@LonelyGuy12
Copy link

this bot wont work without token, please send your token.

What?? Are you idiot?

bro why are you mean, the bot wont work without token, please give the token so i can run the bot.

U r really an idiot why would anyone share the token

Duh, the bot wouldn't work without the token, that's why.

Bro are you joking why will someone share their token go get your own token from https://discord.com/developers/applications

@tomasjoos
Copy link

How do you add a command?

@Raphael-Penning
Copy link

wich discord.py version i just had for that

@sick2as
Copy link

sick2as commented Apr 19, 2022

this bot wont work without token, please send your token.

What?? Are you idiot?

bro why are you mean, the bot wont work without token, please give the token so i can run the bot.

U r really an idiot why would anyone share the token

Duh, the bot wouldn't work without the token, that's why.

bruh no one just make tyour own token DUHHHHHHHHH DUMMY

@Declan-Reid
Copy link

How do you add a command?

For every command use this:

async def ping(message):
    print("Recieved ping from {0.author}".format(message))
    await message.channel.send('pong')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment