#Sending the first message to a given channel

1 messages · Page 1 of 1 (latest)

raven ice
#

Hi,

I have the following code. I'm having issues in figuring out how to send a SocketMessage to a given channel. How do I do that? In case of it matters, I'm using .NET Framework 4.8 due to compatibility reasons.
Thanks in advance!

private static async Task MessageCreate()
{
  SocketTextChannel channel = _client.GetChannel(1234567890) as SocketTextChannel;
  string messageString = "Hello world!";

  // Send a message 'newMessage' of type SocketMessage containing string 'messageString' to channel 'channel' here

  while (true)
  {
    await MessageUpdate(newMessage);
  }
}
#

Hmm, I managed to edit the code so that it should work, but channel returns as null (based on QuickWatch check in the VS debugger)

#
        private static async Task MessageCreate()
        {
            IMessageChannel channel = _client.GetChannel(1034131977386860615) as IMessageChannel;
            string messageString = GetMessage();

            // Send a message 'message' with content of string 'messageString' to channel 'channel' here
            Task<IUserMessage> message = channel.SendMessageAsync(messageString);

            IUserMessage result = message.Result;

            while (true)
            {
                await MessageUpdate(result);
            }
        }
#

channel is indeed null