James Hobday
James Hobday

Reputation: 23

Updating Discord Bot Nickname

I have exhausted a lot of options and attempts at this for the last week or two. I have everything setup right but I am struggling to target the bot's Nickname.

Desired Outcome: I want to update the Discord Bot Nickname (not the username) ever X seconds (in this case 10) to sync with the Binance ticker price.

Issue: targeting the Nickname of the bot properly without issuing a command. I am getting an error that 'me' is undefined

Code:

client.on('ready', () => {
 setInterval(() => {
   client.guilds.cache.find(guild => guild.id === 'GUILD_ID').me.setNickname("$" + '${ticker.DOGEUSDT}');
 }, 10000);
})

Upvotes: 2

Views: 180

Answers (1)

Jannik Schmidtke
Jannik Schmidtke

Reputation: 1247

client.on('ready', () => {
 setInterval(() => {
   client.guilds.cache.get("652865271089856525").members.cache.find(member => member.id === client.user.id).setNickname("$" + `${value}`);
 }, 10000);
})

For me this works absolutely well. Make sure that you are using discord.js v12, by typing npm i discord.js@latest in your terminal.

But I got a little hint for you: If you want to place variables inside a string you have to use ` instead of ' or ".

Upvotes: 1

Related Questions