【问题标题】:Coding a few specific commands for my Discord Bot? (C#, Discord.net 1.02)为我的 Discord Bot 编写一些特定命令? (C#, Discord.net 1.02)
【发布时间】:2018-07-21 13:19:16
【问题描述】:

基本上,我真的很想为我的 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 来说似乎太长了。我没有其他地方可以求助。

【问题讨论】:

    标签: c# bots discord.net


    【解决方案1】:

    使用欢迎信息,您需要订阅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. 
    }
    

    【讨论】:

      猜你喜欢
      • 2020-10-06
      • 2020-02-11
      • 2021-03-13
      • 2020-11-26
      • 2018-12-01
      • 2021-03-12
      • 2020-12-20
      • 2018-04-17
      • 2018-03-04
      相关资源
      最近更新 更多