Closed Aries-Heker closed 3 months ago
import cv2 import discord import ffmpeg import asyncio from discord.ext import commands
TOKEN = 'YOUR_DISCORD_BOT_TOKEN' GUILD_ID = YOUR_GUILD_ID CHANNEL_ID = YOUR_CHANNEL_ID
intents = discord.Intents.default() bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event async def on_ready(): print(f'Logged in as {bot.user}')
async def start_webcam_stream():
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Error: Could not open webcam")
return
while True:
ret, frame = cap.read()
if not ret:
print("Failed to grab frame")
break
# Encode frame to JPEG
ret, buffer = cv2.imencode('.jpg', frame)
if not ret:
print("Failed to encode frame")
break
# Create a filename
filename = 'frame.jpg'
# Save the frame as a file
with open(filename, 'wb') as f:
f.write(buffer)
# Send the frame to Discord
channel = bot.get_channel(CHANNEL_ID)
await channel.send(file=discord.File(filename))
# Sleep for a short duration to control frame rate
await asyncio.sleep(0.1)
cap.release()
@bot.command(name='.webcam live') async def start_stream(ctx): await start_webcam_stream()
bot.run(TOKEN)
idk if whould help but...
did you try to run that?
I will spare you wasted time. Its not possible to make due to API limitations
Ahh got it thanks for reaching out 😁
so we all know that in discord we can turn our cameras on right? well what if there was a way to have live video feed thru the voice channel so instead of just using .webcam photo there would be an additional command called ".webcam live" just a thought though :)