Skip to main content
The examples below cover the patterns that come up most often when building a selfbot with alterself. Each one is self-contained and ready to drop into your project — swap in your token, adjust the constants, and run. Click any accordion to expand the full code.
The simplest possible alterself bot. It connects to the gateway, prints your username when ready, and responds to .ping with your current latency.
Deletes your trigger message and re-sends its content as a clean message in the same channel. The aliases=["say"] parameter means both .echo and .say work.
ctx.delete() removes the original command invocation message. If you lack permission to delete messages in that channel, an HTTPError with code 50013 is raised. Consider wrapping this in a try/except.
Watches every incoming message and adds a heart reaction whenever a specific user posts. Replace TARGET_USER with the user’s numeric ID.
You can extend EMOJI to a list and pick one at random with random.choice(EMOJIS) for more variety.
Prints every incoming direct message to your console with a timestamp. Guild messages are ignored so your logs stay clean.
Groups admin commands inside a Cog class to keep your project organised. The purge command deletes the last n messages in the current channel (default: 10).
Bulk-deleting messages at high speed can trigger rate limits. Add a short asyncio.sleep between deletions if you plan to purge large numbers of messages.
Joins a list of Discord servers from their invite codes, with a 1.5-second delay between each join to stay under rate limits. Runs without a persistent gateway connection.
CaptchaChallenge can be raised by http.join_guild() if Discord requires verification. See the Error Handling guide for details on how to handle it.
Rotates through a list of activities every 60 seconds using a background asyncio task. The task starts automatically once the gateway is ready.
Swap the 60-second interval for any value you like. Avoid going below 30 seconds. Updating presence too frequently can cause Discord to silently drop updates.