There weren't (m)any Discord bots out there that could mass reset usernames for my server. So, I took the initiative and wrote this quick script to get the job done. Hope it helps! This is a simple Discord bot written in Python that listens for a !reset
command. When this command is issued in a public channel, the bot will reset the nicknames of all members in that guild (server) to their default names.
You can install the necessary libraries via pip:
pip install discord.py python-dotenv
- Download this repository onto your computer.
- Create a file named
.env
in the main folder of the project. - Copy and paste the code below into the
.env
file.
BOT_TOKEN = "<api_token>"
- Login to the Discord Developer Portal.
- Create a new application (the name does not matter).
- Go to OAuth2 > General > Reset/Generate Client Secret.
- Replace
<api_token>
with your generated secret. - Run the script (while in the repository's directory):
python3 src/reset_names.py
- The bot requires certain intents to function correctly: message content, guilds, and members. These are set to make sure the bot can read messages and interact with members in a guild.
- Once the bot detects the
!reset
command, it will loop through all members in the guild and reset their nicknames to the default. - It will then send a combined message indicating the nickname reset process. The message includes placeholders for showing the "Before (Nickname)" and "After (Default)" which will be implemented later.
When trying to run the reset_names.py
script, you may encounter an error indicating an "TypeError: expected token to be a str, received NoneType instead". This can happen due to a missing API token or missing .env
file.
Ensure that you have a .env
file in the reset-name-discord-bot
folder, and that you have provided the API token to BOT_TOKEN="<api_token>"
in the .env
file.
A limitation of the script is the bot's permissions don't allow it to reset the server owner's nickname. This is the error code when trying to do so.
(403 Forbidden (error code: 50013): Missing Permissions)
Unfortunately, this error cannot be resolved due to API limitations. My suggestion would be to manually change the owner's nickname to its default state.
If you encounter any issues or if there is any way to make the steps to using the script easier to understand, please open an issue in the repository or contact me.