基本上,我真的很喜欢我的Discord Bot的一些特定命令,但我对C#的经验很少。我的主要目标是:
这是我目前的命令列表:
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来说太长了。我无处可去。
答案 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.
}