Discord.js重命名当前频道

时间:2019-06-28 22:25:48

标签: discord discord.js

我是discord.js的超级新手,但我使用的是带有票务系统的预制机器人,其中用户执行命令来打开票证。我想这样做,以便只有在我的服务器中称为Faulty Admins的工作人员可以通过-rename来根据票证的用途来重命名票证。我只能找到此代码

if(command === `${prefix}openslot`) {

    let embed = new Discord.RichEmbed()
        .setColor("#1bc643")
        .setTitle("Sucessfully opened slot for PREMIUM RANK!")
        .addField("Created At", message.author.createdAt)

        .setDescription("SYSTEM");

    message.channel.sendMessage(embed);
message.guild.channels.find("name", "general").setName("Testing");

.then(newChannel => console.log(Channel's new name is ${newChannel.name})) .catch(console.error);

    return;
}

在线,所以我不太确定该怎么做。我仔细研究了该机器人随附的代码,这似乎是将命令限制为某些角色的代码

if(!message.member.roles.has(message.guild.roles.find(r => r.name == "Faulty Admins").id)) return message.channel.send('Invalid permissions.');

如果您有任何想法,请告诉我。似乎第一个代码段用于更改特定通道的名称,但我希望此命令更改在其中运行该命令的通道的名称。

1 个答案:

答案 0 :(得分:1)

无需搜索频道。就像您可以使用message.channel.send()将消息发送到同一频道一样,您也可以类似地更改频道:

message.channel.setName("testing")
  .catch(console.error);

请参见TextChannel.setName()