I'm working on Server Stats in my server, now I created some Voice Channels for that and everytime the auto refresh function kicks in it will update the name of those channels via the info of users/roles/bots/channels but there is one irritating problem that the name in the SocketVoiceChannel is get(read only)
int nMemberCount = guild.users.count;
ulong idUserCound = 623234360010735636;
SocketVoiceChannel MemberCount = guild.VoiceChannels.Where(x => x.Id == idUserCound).FirstOrDefault();
UserCount.Name = $"👥 Member Count: {nMemberCount}"; // error: 'Name' is read only! help!
error: 'Name' is read only.
What can I do to set the name of the channel to what I need to set it? Is there another way?
The majority of entities in Discord.Net have a ModifyAsync()
implementation, which is used to edit the properties of the given entity. The example here in the docs, demonstrates modifying the user limit for a VoiceChannel
. And here, multiple properties (including name) are modified on a TextChannel
If the voice channel in your code is UserCount
you would have something like
await UserCount.ModifyAsync(prop => prop.Name = $"👥 Member Count: {nMemberCount}");