Last active
February 6, 2021 21:36
-
-
Save nfitzen/191fc73be7f602679c683abca61a0a37 to your computer and use it in GitHub Desktop.
Reverts renames every time someone rechanges your nickname
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# SPDX-FileCopyrightText: 2020-2021 Nathaniel Fitzenrider <https://github.com/nfitzen> | |
# | |
# SPDX-License-Identifier: CC0-1.0 | |
# DISCLAIMER: SELF-BOTTING CAN GET YOU PERMANENTLY BANNED FROM DISCORD! USE AT YOUR OWN RISK! | |
import discord | |
disclaimer = "DISCLAIMER: SELF-BOTTING CAN GET YOU PERMANENTLY BANNED FROM DISCORD! USE AT YOUR OWN RISK!" | |
class Bot(discord.Client): | |
"""Main bot class.""" | |
def __init__(self, **options): | |
super().__init__(**options) | |
self.nickChanges = {} | |
async def on_member_update(self, before, after): | |
"""Automatically updates nickname upon change.""" | |
try: | |
hasChanged = self.nickChanges.pop(after.guild.id) | |
except KeyError: | |
if after == self.user and after.nick != before.nick: | |
# There's probably a better way to do this | |
self.nickChanges[after.guild.id] = True | |
changedNick = after.nick | |
await after.edit(nick=before.nick) | |
print("Name changed from",changedNick,"to",before.nick) | |
async def on_ready(self): | |
global disclaimer | |
print(disclaimer) | |
def get_token(): | |
try: | |
with open('token.txt') as f: | |
token = f.read() | |
except FileNotFoundError: | |
token = get_token_prompt() | |
return token | |
def get_token_prompt(): | |
global disclaimer | |
instructions = """To obtain your token, go to discord.com, press F12/CTRL+SHIFT+I, open the | |
Network tab, and click "Open Discord." Then, filter the URL for "api," click on | |
the top one or so, and look on the right under HTTP headers for "Authorization:" | |
(you may have to scroll down a bit). Paste that here. | |
""" | |
print(disclaimer) | |
print(instructions) | |
token = input("Input your Discord token: ") | |
saveAns = input("Save to token.txt? (Y/N) [Y] ") | |
if not saveAns.lower().startswith('n'): | |
with open('token.txt', 'w') as f: | |
f.write(token) | |
return token | |
bot = Bot() | |
token = get_token() | |
while True: | |
try: | |
bot.run(token, bot=False) | |
except discord.errors.LoginFailure as e: | |
print(e) | |
token = get_token_prompt() | |
except: | |
quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment