我正在使用我的discord bot的流氓异常包 .
当用户通过命令调用bot时,我希望机器人在执行命令之前删除他的消息 .
所以在我的“MessageReceived”-Event中我到目前为止有这个代码:
private async Task MessageReceived(SocketMessage s)
{
var msg = s as SocketUserMessage; // the input
if (msg == null || !msg.Content.StartsWith("!") || msg.Author.IsBot) // return if null, msg is no command, msg is written by the bot
return;
if (msg.Channel is SocketGuildChannel guildChannel) // just delete the command if the msg is written in the guild channel, not a private message channel
await ??? // Delete the command
}
那么有人知道,在那里写什么=?
2 回答
我可以看到你正在为你的机器人使用Discord.NET API .
所以从这个文档here .
看一下
SocketMessage
属性中的Method
列表 . (顺便说一句,看看网页的右侧,你应该能够看到一个允许你轻松导航的栏)您应该能够看到一个名为
DeleteAsync
的方法 . 那就是你想要的 .(截图如下)
对于参数,您可以看到它是
RequestOption
数据类型,默认情况下已为您设置了null
. 您可以更改它,但我强烈建议您使用默认值 .示例:
(对不起,但有些代码字符串是葡萄牙语...这是一个投票系统)