微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通知用户命令需要参数才能在 discord.net 中传递?

如何解决通知用户命令需要参数才能在 discord.net 中传递?

我有一个函数可以提供服务器中其他用户的当前用户状态:

npm i moment 

我想要做的是当用户没有提供参数时,我想通知他这个命令需要一个参数。我怎样才能做到这一点?

解决方法

类似于小 ReplyAsync() 的东西应该可以解决问题。

例如,使用您的代码:

[Command("userstatus"),Summary("Provides you the info of the given user status")]
public async Task UserStatus([Remainder] SocketUser user)
{
    if (user is null)
    {
        await ReplyAsync($"{Context.User.Mention} Please @mention another user to use this command.");
    }
    else
    {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        embedBuilder.AddField("User Status",CommandHandler._discord.GetUser(user.Username,user.Discriminator).Status);
        embedBuilder.AddField("Current Activity",user.Activity);
        await Context.Channel.SendMessageAsync(null,false,embedBuilder.Build());
    }
}

话虽如此,确实存在其他“更复杂”的方法,但我的建议是保持简单;)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。