コード例 #1
0
        public async ValueTask OnMessageCreate(IDiscordMessage message)
        {
            switch (message.Content)
            {
            // Command !ping
            // Replies with the message "Pong".
            case "!ping":
                await _client.SendMessageAsync(message.ChannelId, "Pong");

                break;

            // Command !embed
            // Replies with a example embed.
            case "!embed":
                await _client.SendMessageAsync(message.ChannelId, null, new DiscordEmbed
                {
                    Title       = "Example",
                    Description = "Example embed"
                });

                break;

            // Command !users
            // Show all users of the guild with their normalized name.
            case "!users" when message.GuildId.HasValue:
            {
                var memberNames = (await _client.GetGuildMemberNamesAsync(message.GuildId.Value))
                                  .Select(n => $"- {n.Nickname ?? n.Username} ({n.NormalizedNickname ?? n.NormalizedUsername})");
                var response = string.Join("\n", memberNames);

                await _client.SendMessageAsync(message.ChannelId, response);

                break;
            }

            // Command !spam
            case "!spam" when message.GuildId.HasValue:
            {
                for (var i = 0; i < 10; i++)
                {
                    await _client.SendMessageAsync(message.ChannelId, $"Message {i}");
                }
                break;
            }
            }
        }