Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change username of bot using Discord.js?

I feel like I've tried everything. My bot's name is currently "TestApp" and I would like to change it to something else. Do I have to remove it completely, create a whole new app inside of https://discordapp.com/developers/, assign it a proper name, then add a bot inside there? Then obviously change the token inside my Discord.js application and re-invite the bot to the channel.

I've tried:

  • Change the App Name on https://discordapp.com/developers/
  • msg.guild.members.get(bot.user.id).setNickname("NEWNAMEHERE")
  • Discord.Client.setUsername("NEWNAMEHERE")

Let me know if you can actually change the username/nickname of a Discord bot, without removing it and starting over with the configuration. I can't seem to find this answer anywhere.

like image 577
MortenMoulder Avatar asked Oct 23 '17 21:10

MortenMoulder


2 Answers

With Discord's new Dashboard, it's actually really easy to change the username using ANY language! On your applications page, if you go to the "Bot" tab, you can change both the user avatar as well as the username there. After you hit "save changes" it will apply the new username and avatar to Discord. Like before, you won't notice the change immediately, but it will happen.

OLD ANSWER:

As of Discord.js v11.2, When you create a new bot client using Discord.js, you can use .setUsername on the new client to change the name instead of sending a request to the API. You will not notice the change immediately, but it will happen. To rename the application on the developers page, you just need to click on the application itself.

Here's an example login method to change the name, as stated in the documentation.

const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('ready', function() {
    bot.user.setUsername("MyNewUsername");
}
bot.login("token");

Or, if you have an eval command, you can simply run the below. If your bot client is named something other than "bot", use that instead.

bot.user.setUsername("MyNewUsername");
like image 111
FireController1847 Avatar answered Oct 28 '22 07:10

FireController1847


Well who knew, you can send a PATCH request to their server with your new information in it (you can also change avatar like this):

curl -H 'Authorization: Bot TOKEN_GOES_HERE' -H "Content-Type: application/json" -X PATCH -d '{"username": "NEWNAMEHERE"}' https://discordapp.com/api/users/@me

Found this in their documentation here.

like image 38
MortenMoulder Avatar answered Oct 28 '22 06:10

MortenMoulder