Discord.NET踢命令

时间:2018-12-12 17:20:48

标签: c# sql ms-access discord discord.net

所以我有一个正在为计算机科学项目工作的机器人,而我的kick命令不起作用。我尝试注释掉更新SQL和ReplyAsync行,但它不会踢用户。我为用户使用了错误的数据类型吗?

public class Kick : ModuleBase<SocketCommandContext>
    {
        OleDbConnection con;
        OleDbDataAdapter da;

        [Command("kick")]
        [RequireUserPermission(GuildPermission.KickMembers)]
        [RequireBotPermission(GuildPermission.KickMembers)]
        public async Task KickUser(IGuildUser user, string reason = "No reason provided")
        {
            con = new OleDbConnection();
            con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=BotDB.accdb";
            da = new OleDbDataAdapter();

            con.Open();
            da.InsertCommand = new OleDbCommand($"UPDATE UserData SET NumKick = NumKick + 1 WHERE UserID = '{Convert.ToString(user.Id)}'");
            da.InsertCommand.ExecuteNonQuery();
            con.Close();

            await ReplyAsync($"{user.Nickname} was kicked from the server for '{reason}'");
            await user.KickAsync(reason);
        }
    }

1 个答案:

答案 0 :(得分:1)

我设法解决了这个问题,出于字符串原因,我不得不删除了默认值,并且在InsertCommand区域中,我忘记在SQL之后声明OleDbConnection。