Change user nickname with discord.js

前端 未结 11 1391
清酒与你
清酒与你 2020-12-16 19:15

I wonder if you can help (I search it and nothing...) I am learning how to work with discord.js node and I want to change my user nickname (not the username itself)

11条回答
  •  醉梦人生
    2020-12-16 19:52

    What it looks like is that you are trying to give your bot a nickname To change the bot's nickname use this:

    const Discord = require('discord.js');
    const client = new Discord.Client();
    client.on('ready', () => {
        console.log('I am ready!');
    });
    
    client.on('message', message => {
        if (message.content.toLowerCase().startsWith('changeNick')) {
           var newNickname = message.content.replace("changeNick ", "");
           message.guild.me.setNickname(newNickname);
        }
    });
    

    If you want to change a users nickname you should use this:

    const Discord = require('discord.js');
    const client = new Discord.Client();
    client.on('ready', () => {
        console.log('I am ready!');
    });
    
    client.on('message', message => {
    
        let args = message.content.split(" ");
    
        if(message.content.toLowerCase().startsWith("changeNick")){
            if(!message.mentions.users.first()) return message.channel.send("You didn't specify a user!");
             const user = message.mentions.members.first();
             const username = message.guild.members.cache.find(userI => userI.id == user);
             var newNickname = message.content.replace("changeNick "+args[1], "");
             username.setNickname(newNickname);
        }
    });
    

提交回复
热议问题