Grunwaldt
Grunwaldt

Reputation: 51

C# DSharpPlus How to get a channel by name to use in SendMessageAsync?

I would like to have a GetChannelByName() or some simmilar function to be able to use SendMessageAsync which requires a channel type (DiscordChannel type) as its first parameter. How do you use that in DSharpPlus?

Upvotes: 0

Views: 1563

Answers (1)

Grunwaldt
Grunwaldt

Reputation: 51

I have managed to figure out a way of getting the channel, in my code, updates_channel, which is a DiscordChannel item. I post a snippet of the relevant code just in case someone is having the same problem:


       int numguilds = discord.Guilds.Count;
            
       int numchannels = 0;
                        
       DiscordGuild[] ArrayGuilds;
       DiscordChannel[] ArrayChannels;
                        
       ArrayGuilds = new List<DiscordGuild>(discord.Guilds.Values).ToArray();

       for (ulong z = 0; z < (ulong)numguilds; z++)
       {
           numchannels = ArrayGuilds[z].Channels.Count;

           ArrayChannels = new List<DiscordChannel>(ArrayGuilds[z].Channels).ToArray();

           for (int y = 0; y < numchannels; y++)
           {
               if (ArrayChannels[y].Name == UpdateChannelName)
               {
                   updates_channel = ArrayChannels[y];
                   break;
               }                   
           }

           if (updates_channel != null)
               break;
       }

Upvotes: 2

Related Questions