-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_screen.py
43 lines (35 loc) · 1.56 KB
/
view_screen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import discord
from discord.ext import commands, tasks
from PIL import ImageGrab
import io
import conf
activity = discord.Activity(type=discord.ActivityType.watching, name=f"Wextra's PC||{conf.PREFIX}")
bot = commands.Bot(
command_prefix=conf.PREFIX,
activity=activity,
case_insensitive=True,
intents=discord.Intents.all()
)
# Global variable to store the message containing the embed
current_embed_message = None
@tasks.loop(seconds=3.5)
async def update_screenshot(ctx: commands.Context):
global current_embed_message
# Capture the screen content
screenshot = ImageGrab.grab()
# Save the screenshot to a bytes buffer
img_bytes = io.BytesIO()
screenshot.save(img_bytes, format="PNG")
img_bytes.seek(0)
# Create or edit the existing embed
embed = discord.Embed(title="PC Viewer", description="Viewing the Host's PC", color=0x00ff00)
embed.set_image(url="attachment://pc_screenshot.png")
global current_embed_message
if current_embed_message is None:
# If the current_embed_message doesn't exist, send a new message
current_embed_message = await ctx.send(embed=embed, file=discord.File(img_bytes, filename="pc_screenshot.png"))
elif current_embed_message is not None:
# If the current_embed_message exists, send a new message and delete the old one
new_embed_message = await ctx.send(embed=embed, file=discord.File(img_bytes, filename="pc_screenshot.png"))
await current_embed_message.delete()
current_embed_message = new_embed_message