Answers for "command"

0

command

#require discord, requests, and bs4, config
import discord
import config
from discord.ext import commands
import requests
import bs4
import random
#prefix
bot = commands.Bot(command_prefix=config.prefix)
#on_ready
@bot.event
async def on_ready():
    print('------')
    print('Logged in as')
    print(bot.user.name + "#" + bot.ser.discriminator)
    print('------')
#command that looks for a certain catagory from rule34.xxx site and sends a random image from the category to the channel
@bot.command()
async def rule34(ctx, *, arg):
    #get the url from the site
    url = "https://rule34.xxx/index.php?page=post&s=list&tags=" + arg
    #get the html from the url
    response = requests.get(url)
    #parse the html
    soup = bs4.BeautifulSoup(response.text, "html.parser")
    #get the image url
    img = soup.find("img", {"class": "zoom"})
    #get the image url
    img_url = img["src"]
    #send the image to the channel
    await bot.say(img_url)
#run
bot.run(config.token)
Posted by: Guest on April-02-2022

Browse Popular Code Answers by Language