-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.cs
81 lines (77 loc) · 3.37 KB
/
Bot.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using System.Threading.Tasks;
namespace TestDiscord
{
public class BotConfig
{
public const string token = "Your Bot Token Here";
public const string prefix = "?";
}
public class Bot
{
public DiscordClient DiscordClient { get; private set; }
public CommandsNextExtension CommandsNextExtension { get; private set; }
public async Task RunAsyn()
{
DiscordConfiguration config = new DiscordConfiguration
{
Token = BotConfig.token,
TokenType = TokenType.Bot,
AutoReconnect = true,
MinimumLogLevel = Microsoft.Extensions.Logging.LogLevel.Debug,
Intents = DiscordIntents.AllUnprivileged
};
DiscordClient = new DiscordClient(config);
CommandsNextConfiguration commandConfig = new CommandsNextConfiguration
{
StringPrefixes = new string[]
{
BotConfig.prefix
},
EnableMentionPrefix = true,
EnableDms = false
};
CommandsNextExtension = DiscordClient.UseCommandsNext(commandConfig);
if (CommandsNextExtension != null)
CommandsNextExtension.RegisterCommands<Commands>();
await DiscordClient.ConnectAsync();
await Task.Delay(-1);
}
}
public class Commands : BaseCommandModule
{
[Command("getallguildmemberlist")]
public async Task GetAllGuildMemberList(CommandContext commandContext)
{
System.Collections.Generic.IReadOnlyDictionary<ulong, DiscordGuild> guilds = commandContext.Client.Guilds;
await commandContext.Channel.SendMessageAsync("Guild count " + guilds.Count.ToString());
foreach (System.Collections.Generic.KeyValuePair<ulong, DiscordGuild> guild in guilds)
{
System.Collections.Generic.IReadOnlyCollection<DiscordMember> readOnlyCollections = await guild.Value.GetAllMembersAsync();
await commandContext.Channel.SendMessageAsync("Guild " + guild.Value.Name + " members count " + readOnlyCollections.Count.ToString());
string memberList = string.Empty;
foreach (DiscordMember member in readOnlyCollections)
{
memberList += member.DisplayName + ",";
}
await commandContext.Channel.SendMessageAsync(memberList.TrimEnd(','));
}
}
[Command("getguildmemberlist")]
public async Task GetGuildMemberList(CommandContext commandContext)
{
DiscordGuild guild = commandContext.Member.Guild;
System.Collections.Generic.IReadOnlyCollection<DiscordMember> readOnlyCollections = await guild.GetAllMembersAsync();
await commandContext.Channel.SendMessageAsync("Guild " + guild.Name + " members count " + readOnlyCollections.Count.ToString());
string memberList = string.Empty;
foreach (DiscordMember member in readOnlyCollections)
{
memberList += member.DisplayName + ",";
}
await commandContext.Channel.SendMessageAsync(memberList.TrimEnd(','));
}
}
}