简体   繁体   中英

How can I change a Discord channel name using nodeJS and discordJS?

I'm coding my first discord bot with node.js and discord.js.

The main goal is to give information about a Minecraft server via Discord.

I want to have a channel that every some time, updates its name to:

There are [x] active players in this server.

I have a variable that updates every 1 minute with the number of people currently playing.

How can I update a channel name knowing its ID?

I checked the discord.js documentation but I'm a beginner in JS and I don't fully understand what I have to do.

This should be the bare minimum to set the guild name. I imagine your bot will need specific permisons to be able to do so thought. Make sure to have a play about with all the methods in the docs!

var Discord = require('discord.js');
var client = new Discord.Client();

client.on('ready', ()=>{
    let guild = client.guilds.get( GUILD_ID_HERE );
    let channel = guild.channels.get( CHANNEL_ID_HERE )
    channel.setName('My Cool new guild name')
})

client.login( YOUR_BOT_TOKEN );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM