Hello! Is what Mosu and T-taku. I have some free time in Corona, so I decided to write an article! Please keep in touch with me ...: boy_tone1:
https://discordapp.com/oauth2/authorize?client_id=476012428170362880&permissions=2147347828&scope=bot This bot is run by me T-taku, and if you want to see what the screenshot command looks like, please put it in and give it a try!
Create a bot that will give you a screenshot of your site on Discord! Please note: ** This is not an introduction to Discord.py. ** For account creation, see the great article below: here
This time we will make it on the premise of Windows 10. In addition, we will proceed on the assumption that Google Chrome is also included.
Install the Chrome Driver that suits your environment from here. Please note that if you do not enter the correct version, you will get an error!
pip install discord.py pillow chromedriver chromedriver-binary selenium
Let's implement it now! First, let's take a screenshot.
from PIL import Image
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
Web="https://yahoo.co.jp"
FILENAME = "screen.png "
options=Options()
options.set_headless(True)
options.add_argument('--disable-dev-shm-usage')
options.add_argument('start-maximized')
options.add_argument('disable-infobarse')
options.add_argument('--disable-extensions')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.binary_location="Where there is Chrome"
driver=webdriver.Chrome(chrome_options=options,executable_path=r"Chrome driver location")
driver.get(web)
driver.set_window_size(1280, 720)
driver.save_screenshot(FILENAME)
driver.quit()
It is designed to work at a minimum. (Perhaps...)
import discord
from discord.ext import commands
from PIL import Image
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
bot = commands.Bot(command_prefix='!',activity=d.Activity(name='During startup!',type=d.ActivityType.watching))
@bot.event
async def on_ready():
#Login
print('Login infomation>>>')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.event
async def on_message(message):
ctx = await bot.get_context(message)#Take ctx
if message.author.bot:
return #Does not respond to bots
await bot.invoke(ctx)
@bot.command()
async def ss(ctx,web):
try:
FILENAME = "screen.png "
options=Options()
options.set_headless(True)
options.add_argument('--disable-dev-shm-usage')
options.add_argument('start-maximized')
options.add_argument('disable-infobarse')
options.add_argument('--disable-extensions')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.binary_location="Where Chrome is"
driver=webdriver.Chrome(chrome_options = options,executable_path=r"Where the Chrome driver is")
if not "http" in str(web):
try:
driver.get("http://"+str(web))
except:
driver.get("https://"+str(web))
else:
driver.get(str(web))
if 'IP addres' in driver.page_source:
await ctx.send("You cannot access this web page.")
else:
driver.set_window_size(1280, 720)
driver.save_screenshot('screenshot.png')
file = discord.File("screenshot.png ", filename="image.png ")
embed = d.Embed(title="screenshot", description=f"{web}")
embed.set_image(url="attachment://image.png ")
await ctx.send(file=file,embed=embed)
driver.quit()
except:
await ctx.send("Access was not possible due to an error.")
bot.run("TOKEN HERE")
How was it? I made an article with a little difficulty. Please add it to your bot!
As I said at the beginning of the article, if you add my bot, it will encourage the creation of the article and the development of the bot, so thank you!: https://discordapp.com/oauth2/authorize?client_id=476012428170362880&permissions=2147347828&scope=bot
If you find it helpful, I would be more than happy to receive LGTM!
Well then! (I would be grateful if you could tell me if you made a mistake!)
Recommended Posts