Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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')
@ToxicRT

This comment has been minimized.

Copy link

@ToxicRT ToxicRT commented Dec 20, 2019

So useful people like you are the best, thanks now i'm going to learn python yay

@Raydarui

This comment has been minimized.

Copy link

@Raydarui Raydarui commented Mar 1, 2020

How do I add gifs to the messages sent by the bot?

@truxyt-creator

This comment has been minimized.

Copy link

@truxyt-creator truxyt-creator commented Mar 17, 2020

How do I add gifs to the messages sent by the bot?

With this code:

@bot.command()
async def ping(ctx):
await ctx.send('¡Pong!<a:emoji-name:emoji-id>')

@Raydarui

This comment has been minimized.

Copy link

@Raydarui Raydarui commented Mar 17, 2020

yes but, this is for add emojis, I need add gifs from a page of gifs, giphy for example

@felincoli

This comment has been minimized.

Copy link

@felincoli felincoli commented May 8, 2020

yes but, this is for add emojis, I need add gifs from a page of gifs, giphy for example

u need to call an api

@tovade

This comment has been minimized.

Copy link

@tovade tovade commented Jun 15, 2020

how do u make the status playing or listening to helping server

@devjaime

This comment has been minimized.

Copy link

@devjaime devjaime commented Jul 19, 2020

existe un pequeño problema al buscar el video lo solucione reemplazando la expresión regular search_results = re.findall( r"watch\?v=(\S{11})", html_content.read().decode())

@VideoCarp

This comment has been minimized.

Copy link

@VideoCarp VideoCarp commented Jul 26, 2020

I was just trying to figure out how to send an embed on discord.py and came across this bot. Helpful.

@MaxSzmid

This comment has been minimized.

Copy link

@MaxSzmid MaxSzmid commented Jul 27, 2020

existe un pequeño problema al buscar el video lo solucione reemplazando la expresión regular search_results = re.findall( r"watch\?v=(\S{11})", html_content.read().decode())

Agradezco tu aporte, tenia un problema con esa linea, me respondia con una lista vacía por la expresion regular. Muchas gracias!

@PoLoRsiTo

This comment has been minimized.

Copy link

@PoLoRsiTo PoLoRsiTo commented Aug 14, 2020

search_results = re.findall( r"watch?v=(\S{11})", html_content.read().decode())

Gracias, me ha sservido mucho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.