Discord.Net - 如何使用“@”制作Bot Ping用户

时间:2018-02-18 19:27:26

标签: c# tags bots discord discord.net

我正在编写一个基于搜索参数检索图像的机器人。当机器人在命令之后返回消息时,我希望机器人警告用ping发送命令的用户。 (使用不一致中的“@”符号通知消息)。

这是我到目前为止所得到的:

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

我能够正确地抓住命令的作者并按原样发送 -

频道输出:

enter image description here

但是,它实际上并不是作为标签发送的,只是纯文本。

有没有办法真正通知用户?

2 个答案:

答案 0 :(得分:3)

是的,使用User.Mention

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

您也可以将他们的ID放在<@>之间。例如,"Hello <@1234>"

答案 1 :(得分:0)

关于C#6,我最喜欢的一件事是你也可以使用String Interpolation。在Discord.Net中非常有用!

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