Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
I want to change nickname of discord bot

I want to change the name of a discord bot and I have read numerous tutorials and Stack Overflow posts and I still cannot get it. The code is primarily taken from open source bot code, so I know it works (something with my bot setup maybe?)

As I understand it, this code loops through each guild the bot is a member of and sets the nickname.

I found the botId by right clicking the bot in the channel and copying ID.

const { guildId } = require('../config');

module.exports = (client, botId, nickname) => {
 client.guilds.cache.forEach((guild) => {
    const { id } = guild;

    client.guilds.cache
    .get(id)
    .members.cache.get(botId)
    .setNickname(nickname);
  });
};

The bot shows up in the channel (after using oauth2 url), so I'm assuming that means they are a member of the guild.

However, when running this code the bot is not found. I've tried several things from other posts like guild.array() to try and see a full list of the members in the guild, but nothing has worked.

const guild = client.guilds.cache.get('943284788004012072');
const bot = guild.members.cache.get('956373150864642159')
if (!bot) return console.log('bot not found');

Here is the full bot

require('dotenv').config();

const { Client, Intents } = require('discord.js');

const eventBus = require('../utils/events/eventBus');
const setNickname = require('../utils/setNickname');

const getPrice = require('../modules/statsGetters/getPriceDEX');

const { bots } = require('../config');

const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});

client.once('ready', async () => {
  console.log('DEX Price Watch Bot Ready');

  client.user.setPresence({
    activities: [{ name: 'DEX Price', type: 'WATCHING' }],
    status: 'online',
  });

  const price = await getPrice();
  setNickname(client, bots.priceDEX, price);

  eventBus.on(drip.update, async () => {
    const price = await getPrice();
    setNickname(client, bots.priceDEX, price); //update price in config file
  });
});

client.login(process.env.DISCORD_PRICE_DEX);
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

This is the sample of changing bot's nickname for every guild that bot joined

client.guilds.cache.forEach((guild) => { //This is to get all guild that the bot joined  
     const nickname = args.slice(0).join(" ") //You wanted to change nickname
     guild.me.setNickname(nickname); //setting the nickname of your bot
});
about 4 years ago · Juan Pablo Isaza Relatório

0

I believe you're doing it wrong. Docs: https://discord.js.org/#/docs/discord.js/stable/class/GuildMember?scrollTo=setNickname

I would suggest using this module code:

const { guildId } = require('../config');

module.exports = (client, nickname) => {
    client.guilds.cache
    .get(guildId).me.setNickname(nickname);
};

And use it in this way in your main bot code: setNickname(client, price)

Edit: Oh wait, I just realised you didn't use the correct intents (guild members), so you definitely need to use guild.me (as written above by me) or use guild.members.fetch() as it fetches members which aren't cached. More info: https://discord.js.org/#/docs/discord.js/stable/class/GuildMemberManager?scrollTo=fetch

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda