I am coding a discord bot, and I want it to send a message to a server default channel whenever the bot joins a new server.
Here is my code
client.JoinedGuild += async guild =>
var channel = guild.DefaultChannel;
A discord update months ago removed
defaultChannel property. Which means that servers now do not need to have a default channel at all.
(You can even delete all channel in your server!)
Which also means
Guild.DefaultChannel property will not work as intended anymore.
(Correct me if I am wrong, but if a server still has a
#general channel, the property will work as intended.)
Discord.NET v2+ have a working
DefaultChannel property. (It uses its own set of algorithm to determine which would be the default channel for the guild.)
The source code for the algorithm is here. (Line 66-69)
Looking at the algorithm, you may want to be slightly cautious about using it, if your bot have permission to send messages everywhere, the
DefaultChannel property would simply be the first channel in the server's channel list.
(And it would be bad news if that was a readme channel)