user9377936
user9377936

Reputation:

Discord.Net -- How to make Bot Ping users with "@"

I'm working on coding a bot that will retrieve an image based on search parameters. When the bot returns the message after the command, I want the bot to alert the user that sent the command with a ping. (the notification of a message using the "@" symbol in discord).

Here's what I've got so far:

await Context.Channel.SendMessageAsync("@" + Context.Message.Author + "\n" + imageNode.Attributes["src"].Value);

I'm able to correctly grab the author of the command and it sends as it should--

Output in channel:

enter image description here

However, it's not actually sent as a tag, just plain text.

Is there a way to actually ding the user with a notification?

Upvotes: 6

Views: 32931

Answers (2)

Solarcloud
Solarcloud

Reputation: 605

One of my favorite things about C# 6 is that you can also use String Interpolation. Very useful in Discord.Net!

var id = Context.Message.Author.Id;
await Context.Channel.SendMessageAsync($"<@{id}> \n {imageNode.Attributes["src"].Value}";

Upvotes: 2

Wright
Wright

Reputation: 3424

Yes, using User.Mention.

await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + "\n" + imageNode.Attributes["src"].Value);

You can also just put their id in between <@>. For example, "Hello <@1234>"

Upvotes: 8

Related Questions