【问题标题】:How to change username of bot using Discord.js?如何使用 Discord.js 更改机器人的用户名?
【发布时间】:2018-04-04 13:32:22
【问题描述】:

我觉得我已经尝试了一切。我的机器人名称目前是“TestApp”,我想将其更改为其他名称。我是否必须完全删除它,在https://discordapp.com/developers/ 中创建一个全新的应用程序,为其分配一个正确的名称,然后在其中添加一个机器人?然后显然更改我的 Discord.js 应用程序中的令牌并重新邀请机器人进入频道。

我试过了:

让我知道您是否可以真正更改 Discord 机器人的用户名/昵称,而无需删除它并重新开始配置。我似乎在任何地方都找不到这个答案。

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

    使用 Discord 的新仪表板,使用任何语言更改用户名实际上真的很容易!在您的应用程序页面上,如果您转到“机器人”选项卡,您可以在那里更改用户头像和用户名。点击“保存更改”后,它会将新的用户名和头像应用到 Discord。和以前一样,您不会立即注意到变化,但它会发生。

    旧答案:

    从 Discord.js v11.2 开始,当您使用 Discord.js 创建新的机器人客户端时,您可以在新客户端上使用 .setUsername 来更改名称,而不是向 API 发送请求。您不会立即注意到变化,但它会发生。要在开发者页面上重命名应用程序,您只需单击应用程序本身即可。

    这是一个更改名称的示例登录方法,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");
    

    或者,如果你有一个 eval 命令,你可以简单地运行下面的命令。如果您的机器人客户端被命名为“bot”以外的名称,请改用它。

    bot.user.setUsername("MyNewUsername");
    

    【讨论】:

      【解决方案2】:

      谁知道呢,你可以向他们的服务器发送一个 PATCH 请求,其中包含你的新信息(你也可以像这样更改头像):

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

      在他们的文档here 中找到了这个。

      【讨论】:

        【解决方案3】:
        const Discord = require('discord.js')
        const client  = new Discord.Client()
        
        client.on('message', (msg) =>{
        if(msg.author.bot || msg.channel.type == "dm" || msg.channel.type== 'group')return
        if(msg.content.startsWith(prefix) != true)return
        if(msg.content.startsWith(`${prefix}nick`)){
              if(msg.author.id != ownerID)
             msg.guild.members.get(client.user.id).setNickname(/*'Nickname goes here'*/)
          }
        })
        

        【讨论】:

        • const Discord = require('discord.js') const client = new Discord.Client() client.on('message', (msg) =>{ if(msg.author.bot || msg.channel.type == "dm" || msg.channel.type== 'group')return if(msg.content.startsWith(prefix) != true)return const args = msg.content.slice(prefix.length).split(' '); if(msg.content.startsWith(${prefix}nick)){ if(msg.author.id != ownerID) msg.guild.members.get(client.user.id).setNickname(args.toLocaleString()) } }) if you want to do that with custom input lul
        猜你喜欢
        • 2015-12-03
        • 2020-12-10
        • 2021-01-11
        • 2019-02-20
        • 2021-05-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-08
        相关资源
        最近更新 更多