I’m working on a Discord bot and wondering if there’s a way to make it open web pages on the person who sent the command, not on my server where the bot runs.
Here’s what I tried so far:
import webbrowser
import discord
bot = discord.Client()
@bot.event
async def on_message(msg):
if msg.author == bot.user:
return
if msg.content.startswith('launch reddit'):
webbrowser.open('https://reddit.com')
The problem is this opens Reddit on my computer (where the bot is hosted) every time someone uses the command. Is there any method to make the website open on the user’s device who actually typed the message? I want the bot to respond to commands like ‘launch reddit’ by opening the site in the user’s browser, not mine. Is this even technically possible with Discord bots?
Can’t be done - Discord bots run on remote servers and have zero access to users’ browsers or local systems. The webbrowser module only works on whatever machine runs your Python script, not the user’s computer.
I hit this same wall building my first bot last year. Ended up using embedded messages with clickable URLs instead. You can make them look professional with Discord’s embed formatting: await msg.channel.send(embed=discord.Embed(title="Reddit", url="https://reddit.com", description="Click to visit Reddit")). Not automatic, but gets the job done without security issues. Most users prefer it anyway since they control what opens on their device.
yeah, it’s def not gonna happen. bots just can’t run codes locally on users’ machines due to major security issues. if they could, it would open up a ton of risks. stick with sending links in chat or using embeds to keep it safe!
Nope, can’t be done because of security restrictions. Discord bots run server-side and can’t access users’ local machines or browsers. That’s intentional - imagine if any bot could run commands on your computer! The webbrowser module you’re using will always open URLs on the server hosting your bot, which is why Reddit keeps opening there instead of for users. There’s no Discord API method or hack around this. Your best bet is sending clickable links in chat. Users click them to open sites in their browsers. It’s an extra step but keeps things secure while doing basically the same thing.