为我的Discord Bot编写一些特定的命令? (C#,Discord.net 1.02)

时间:2018-02-11 04:50:39

标签: c# bots discord.net

基本上,我真的很喜欢我的Discord Bot的一些特定命令,但我对C#的经验很少。我的主要目标是:

  • 欢迎致新人的致辞。 (私下,对新用户。没有人看到它,但通过服务器新人)
  • 等待输入特定消息。输入此消息后,机器人会向用户添加一个角色,并删除已键入的用户消息(以便新用户不会看到消息并使用它而不是读取规则,就像我打算让他们先查看一样。)
  • 定时器功能,只要新成员加入即可启用。此计时器将持续3天,如果新用户未在该时间段内完成第二项任务,他们将被踢,直到找到新的邀请。
  • 除了输入的特定消息之外的任何其他内容将尝试3次尝试。如果用户没有在输入中键入正确的单词,则每次都会向他们发出警告,直到尝试次数达到3.超过3后,他们将被踢,直到他们找到新的邀请。

这是我目前的命令列表:

using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
namespace BooleanBot.Modules
{
public class commands : ModuleBase<SocketCommandContext>
{

    [Command("help")]
    public async Task help()
    {
        var a = new Discord.EmbedBuilder();
        a.WithTitle("Commands");
        a.WithDescription("General Commands\n-- .help // Gives list of commands to use");
        Discord.IDMChannel gencom = await Context.Message.Author.GetOrCreateDMChannelAsync();
        await gencom.SendMessageAsync("", false, a);
        await gencom.CloseAsync();
    }
    [Command("kick")]
    [RequireBotPermission(Discord.GuildPermission.KickMembers)]
    [RequireUserPermission(Discord.GuildPermission.KickMembers)]
    public async Task KickAsync(Discord.IGuildUser user, [Remainder] string reason)
    {
        if (user.GuildPermissions.KickMembers)
        {
            var b = new Discord.EmbedBuilder();
            b.WithTitle("User Kicked");
            b.WithDescription(user.Username + "was kicked.");
            await Context.Channel.SendMessageAsync("", false, b);
            await user.KickAsync();
        }
    }

    [Command("postwelcome")]
    public async Task welcome()
    {
        var b = new Discord.EmbedBuilder();
        b.WithTitle("Welcome to the Anthamation Server! I'm Antha-bot, the housekeeper! My server prefex is !Yo. Let's get started!");
        b.WithDescription("Before you can do ANYTHING, you must go to #rules-and-access channel and read through the rules first! You will also find instructions on how to access the channels! PLEASE NOTE: If you are not a verified member within 3 days or type in something OTHER than the desired answer, you will be kicked automatically. See you on the other side!");
        await Context.Channel.SendMessageAsync("", false, b);
    }
}

}

非常抱歉,如果这对Stackoverflow来说太长了。我无处可去。

1 个答案:

答案 0 :(得分:0)

如果您有欢迎邮件,则需要订阅UserJoined操作。代码中的其他地方我假设你有client.MessageReceived += client_MessageReceived;的内容。要订阅UserJoined操作,您需要添加client.UserJoined += client.UserJoined;。然后,一旦你完成了它,你就可以执行client_UserJoined()代码。

private async Task client_UserJoined(SocketGuildUser arg)
{
    // whatever you put here will execute when a user joins. 
}