The right proxy type for discord.py
Any plan works for a bot. A sticky session keeps its connection on one IP address.
The values to enter in discord.py
Every PiratProxies plan comes down to four values: host, port, username and password. Here they are for Residential; your own username and password are on your plan page.
| Host | resi.piratproxies.com |
|---|---|
| HTTP port | 8080 |
| SOCKS5 port | 1080 |
| Username | USERNAME |
| Password | shown on your plan page |
There is no separate country or session field: both are part of the username. Your plan page has a generator that writes it, and Targeting and sessions describes each piece.
Setting it up in discord.py
- Pass
proxywith the address andproxy_authwith the username and password when creating the bot.
Code: discord.py through a proxy
Python
import aiohttp
import discord
from discord.ext import commands
bot = commands.Bot(
command_prefix="!",
intents=discord.Intents.default(),
proxy="http://resi.piratproxies.com:8080",
proxy_auth=aiohttp.BasicAuth("USERNAME-country-us-time-600-session-a1b2c3d4", "PASSWORD"),
)Put your own login from the plan page in place of USERNAME and PASSWORD. The example calls an IP-check service, so what it prints is the address your request came from.
Should discord.py rotate IPs or keep one?
When discord.py plays one visitor across several steps, a sticky session keeps the IP address unchanged from start to finish. When every run stands alone, drop the session and each run begins from a new address.
Here is what a sticky username looks like:
USERNAME-country-us-time-600-session-a1b2c3d4When discord.py will not connect
- Use a sticky username. The bot holds one long connection to Discord, and it should stay on one IP address.
- Error
407means the login was refused. Copy the username and password from your plan page once more, and make sure no space crept in and the username was not cut short. - An IP in the wrong country nearly always comes from the username, since the country code lives there. Other fixes.
discord.py and proxies: questions
Which PiratProxies plan suits discord.py best?
Any plan works for a bot. A sticky session keeps its connection on one IP address.
Words used in this guide: headless browser, rotating proxy, sticky session, proxy authentication.
discord.py belongs to its own developers, and PiratProxies has no connection with them; we name it only to say what this guide covers. Follow the rules of the sites you visit and our acceptable use policy.