question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get and Send message from and to specific channel and direct message

See original GitHub issue

Hello Sorry if I write this to bad section but I didn’t see support menu. So my question is how can I send and get messages from and to specific channel? Other is, how can I get direct message and send to direct message? I try to create a chat bot and my plan is that if someone write a direct message to chatbot then the chat bot answer to message in the same direct message. Same with channel. For example I create a channel “test” channel and someone write something in “test” channel then the bot answer to “test” channel.

I tried somehow create a solution to this, but the chat bot get messages from everywhere not from specific parts.

My code is this: `

client.MessageReceived += async (s, e) =>
          {
              if (!e.Message.IsAuthor)
              {
                  var responseString = await httpclient.GetStringAsync("http://api.program-o.com/v2/chatbot/?" + e.Message.Text + "&convo_id=exampleusage_1231232&format=json");
                  Botvalasza botvalasza = JsonConvert.DeserializeObject<Botvalasza>(responseString);
                  Console.WriteLine(botvalasza.botsay);

                  var channel = e.Server.FindChannels("test", ChannelType.Text).FirstOrDefault();
               
                  await channel.SendMessage(botvalasza.botsay);
              }
          };

`

This code send to specific channel answers but not to direct messages and this get all messages from all channels and direct messages. Thank you in advance for your answer 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
Chrisdbhrcommented, Aug 24, 2020

For anyone who arrived here from Google like me:

I managed to check if a message is a Direct Message casting the source message channel to IDMChannel. An example:

if (socketMessage.Channel is IDMChannel dmChannel) {
	// if arrived here, it is a DM
}
1reaction
StrangerGithubercommented, Jun 24, 2017

Ok, I found a solution. 😄 If someone want same thing as I then here is the solution.

If you want check if the message come via DM then you can use this:

if (e.Channel.Name == e.User.PrivateChannel.Name)
{
//your code
}

If the message come via specific channel then here is the code:

if (e.Channel.Name == "test")
{
//your code
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sending message to specific channel in discord.js
There are three ways of sending message to a specific channel. 1. Using a fetch method
Read more >
Send a Message to a Specific Channel Using Discord.py
Synthetic Everything shows you how to send a message to a specific channel using discord.py Have A Suggestion For A New Video Comment...
Read more >
Send a Slack Direct Message for new Channel Messages
Send a direct message to a user or yourself from the Slackbot. ... Triggers when a new message is posted to a specific...
Read more >
Sending messages
This guide will help you learn a basic way to accomplish this, and show you the paths you can take.
Read more >
Manage notifications for specific channels and direct ...
Configure conversation-specific notifications · Open a channel or group DM. · Click the channel or member names in the conversation header. · Below...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found