【问题标题】:how to kick people in discord C#如何在不和谐的 C# 中踢人
【发布时间】:2019-08-07 19:55:51
【问题描述】:

我有一些代码旨在让人们不和谐

 namespace bot.Core.Commands
 {
    public class Kick : ModuleBase<SocketCommandContext>
    {
        [Command("kick"), Summary("")]
        public async Task kick(IGuildUser User, string reason = "no reason")
        {
            User.KickAsync(reason);
        }
    }
 }

            int argpos = 0;
        if (!(Message.HasStringPrefix("$", ref argpos) || Message.HasMentionPrefix(Client.CurrentUser, ref argpos))) return;

        var result = await Commandss.ExecuteAsync(context, argpos);
        if(!result.IsSuccess)
        {
            await context.Channel.SendMessageAsync("Command not found or has failed, Commands can also only be ran by an administrator");
        }

但是它总是抛出 Command not found 或失败,Commands 也只能由管理员运行。任何人都可以解释为什么? 除了这个之外,所有其他命令都可以正常工作。提前致谢

我在 c# vs 2017 上使用 windows

也不是权限

【问题讨论】:

  • 你在用Discord.Net吗?
  • 是的,我是和 vs 2017

标签: c# discord


【解决方案1】:

需要在命令参数中reason的声明前加上[Remainder]

 namespace bot.Core.Commands
 {
    public class Kick : ModuleBase<SocketCommandContext>
    {
        [Command("kick"), Summary("Kicks a user from the guild.")]
        public async Task KickCommand(IGuildUser user, [Remainder] string reason = "no reason")
        {
            user.KickAsync(reason);
        }
    }
 }

否则,在如下命令中:

"$kick @Username Sending NSFW Pics"

“发送”之后的所有内容都将被视为额外参数,而不是reason 的一部分,因此该命令将失败,因为它只接受两个参数。添加[Remainder] 告诉命令查看之后作为同一参数的一部分键入的所有内容。

也就是说,如果您不指定原因,该命令应该可以工作。这是真的?你有没有试过在不记录原因的情况下踢? (只是user.KickAsync()

【讨论】:

    猜你喜欢
    • 2020-09-23
    • 2021-08-08
    • 2020-04-29
    • 2021-01-24
    • 2019-02-22
    • 2021-06-30
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多