Skip to content

Instantly share code, notes, and snippets.

@GrunclePug
Last active March 9, 2022 14:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save GrunclePug/64f5d17148435ca8975ae51ac764f553 to your computer and use it in GitHub Desktop.
Save GrunclePug/64f5d17148435ca8975ae51ac764f553 to your computer and use it in GitHub Desktop.
C# Discord Bot
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class Boobs : ModuleBase<SocketCommandContext>
{
[Command("boobs")]
[RequireUserPermission(ChannelPermission.AttachFiles)]
[RequireNsfw]
public async Task BoobPic()
{
using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
{
client.BaseAddress = new Uri("https://nekos.life/api/v2/img/");
HttpResponseMessage response = client.GetAsync("boobs").Result;
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
var result1 = result.Replace("{", " ");
var result2 = result1.Replace("}", " ");
var result3 = result2.Replace("\"url\":", " ");
var result4 = result3.Replace("\"", " ");
await ReplyAsync(result4);
}
}
}
}
//Discord Bot By: @GrunclePug#7015
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class Help : ModuleBase<SocketCommandContext>
{
[Command("help")]
public async Task PingAsync()
{
EmbedBuilder builder = new EmbedBuilder();
builder.AddField("NepuBot Command Help", "Bot created by @GrunclePug#7015")
.AddInlineField("Commands",
"**help** | Brings you here" +
"\n**serverinfo** | See info on the current server" +
"\n**userinfo** | See info on a certain user" +
"\n**ping** | Checks the delay between you and the bot" +
"\n**bean** | Bean a member" +
"\n**neko** | Post a random neko pic (you need attach files perm in that channel)")
.AddInlineField("Staff Commands",
"\n**ban** | Ban a member (requires server ban permission)" +
"\n**purge** | Purge x messages, where x is 2-100" +
"\n**role add** | usage: n!role add @user role (put role in quotations)" +
"\n**role remove** | usage: n!role remove @user role (put role in quotations)")
.AddInlineField("NSFW Commands",
"\n**lewd** | Post a random NSFW Neko (requires NSFW channel)" +
"\n**pussy** | Post a random pussy pic (requires NSFW channel)" +
"\n**boobs** | Post a random boob pic (requires NSFW channel)" +
"\n**nekogif** | Post a random NSFW Neko Gif (requires NSFW channel)" +
"\n**lesbian** | Post a random NSFW lesbian pic (requires NSFW channel)")
.WithColor(Color.Magenta)
.WithThumbnailUrl(Context.Guild.IconUrl);
await ReplyAsync("", false, builder.Build());
}
}
}
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class Lesbian : ModuleBase<SocketCommandContext>
{
[Command("lesbian")]
[RequireUserPermission(ChannelPermission.AttachFiles)]
[RequireNsfw]
public async Task LesbianPic()
{
using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
{
client.BaseAddress = new Uri("https://nekos.life/api/v2/img/");
HttpResponseMessage response = client.GetAsync("les").Result;
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
var result1 = result.Replace("{", " ");
var result2 = result1.Replace("}", " ");
var result3 = result2.Replace("\"url\":", " ");
var result4 = result3.Replace("\"", " ");
await ReplyAsync(result4);
}
}
}
}
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class LewdNeko : ModuleBase<SocketCommandContext>
{
[Command("lewd")]
[RequireUserPermission(ChannelPermission.AttachFiles)]
[RequireNsfw]
public async Task LewdNekoPic()
{
using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
{
client.BaseAddress = new Uri("https://nekos.life/api/v2/img/");
HttpResponseMessage response = client.GetAsync("lewd").Result;
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
var result1 = result.Replace("{", " ");
var result2 = result1.Replace("}", " ");
var result3 = result2.Replace("\"url\":", " ");
var result4 = result3.Replace("\"", " ");
await ReplyAsync(result4);
}
}
}
}
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class Neko : ModuleBase<SocketCommandContext>
{
[Command("neko")]
[RequireUserPermission(ChannelPermission.AttachFiles)]
public async Task NekoPic()
{
using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
{
client.BaseAddress = new Uri("https://nekos.life/api/v2/img/");
HttpResponseMessage response = client.GetAsync("neko").Result;
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
var result1 = result.Replace("{", " ");
var result2 = result1.Replace("}", " ");
var result3 = result2.Replace("\"url\":", " ");
var result4 = result3.Replace("\"", " ");
await ReplyAsync(result4);
}
}
}
}
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class NekoGif : ModuleBase<SocketCommandContext>
{
[Command("nekogif")]
[RequireUserPermission(ChannelPermission.AttachFiles)]
[RequireNsfw]
public async Task NekoGifPic()
{
using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
{
client.BaseAddress = new Uri("https://nekos.life/api/v2/img/");
HttpResponseMessage response = client.GetAsync("nsfw_neko_gif").Result;
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
var result1 = result.Replace("{", " ");
var result2 = result1.Replace("}", " ");
var result3 = result2.Replace("\"url\":", " ");
var result4 = result3.Replace("\"", " ");
await ReplyAsync(result4);
}
}
}
}
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class Pussy : ModuleBase<SocketCommandContext>
{
[Command("pussy")]
[RequireUserPermission(ChannelPermission.AttachFiles)]
[RequireNsfw]
public async Task PussyPic()
{
using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
{
client.BaseAddress = new Uri("https://nekos.life/api/v2/img/");
HttpResponseMessage response = client.GetAsync("pussy").Result;
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
var result1 = result.Replace("{", " ");
var result2 = result1.Replace("}", " ");
var result3 = result2.Replace("\"url\":", " ");
var result4 = result3.Replace("\"", " ");
await ReplyAsync(result4);
}
}
}
}
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
[Group("role")]
public class role : ModuleBase<SocketCommandContext>
{
[Command("add")]
[RequireUserPermission(GuildPermission.ManageRoles)]
public async Task AddRole(SocketGuildUser user, string role)
{
var Role = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == $"{role}");
await user.AddRoleAsync(Role);
await ReplyAsync($"Role given to {user}: {Role}");
}
[Command("remove")]
[RequireUserPermission(GuildPermission.ManageRoles)]
public async Task RemoveRole(SocketGuildUser user, string role)
{
var Role = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == $"{role}");
await user.RemoveRoleAsync(Role);
await ReplyAsync($"Role removed from {user}: {Role}");
}
}
}
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Reflection;
using System.Threading.Tasks;
namespace DiscordBot
{
class Program
{
static void Main(string[] args) => new Program().RunBotAsync().GetAwaiter().GetResult();
private DiscordSocketClient _client;
private CommandService _commands;
private IServiceProvider _services;
public async Task RunBotAsync()
{
_client = new DiscordSocketClient();
_commands = new CommandService();
_services = new ServiceCollection()
.AddSingleton(_client)
.AddSingleton(_commands)
.BuildServiceProvider();
string botToken = "BOT_TOKEN";
//event subscriptions
_client.Log += Log;
_client.UserJoined += AnnounceUserJoined;
await RegisterCommandAsync();
await _client.LoginAsync(TokenType.Bot, botToken);
await _client.StartAsync();
await _client.SetGameAsync("n!help | GrunclePug#7015");
await Task.Delay(-1);
}
private async Task AnnounceUserJoined(SocketGuildUser user)
{
var guild = user.Guild;
var channel = guild.DefaultChannel;
await channel.SendMessageAsync($"Welcome {user.Mention}");
}
private Task Log(LogMessage arg)
{
Console.WriteLine(arg);
return Task.CompletedTask;
}
public async Task RegisterCommandAsync()
{
_client.MessageReceived += HandleCommandAsync;
await _commands.AddModulesAsync(Assembly.GetEntryAssembly());
}
private async Task HandleCommandAsync(SocketMessage arg)
{
var message = arg as SocketUserMessage;
if (message is null || message.Author.IsBot) return;
int argPos = 0;
if (message.HasStringPrefix("n!", ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos))
{
var context = new SocketCommandContext(_client, message);
var result = await _commands.ExecuteAsync(context, argPos, _services);
if (!result.IsSuccess)
Console.WriteLine(result.ErrorReason);
}
}
}
}
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class Ping : ModuleBase<SocketCommandContext>
{
[Command("ping")]
public async Task PingAsync()
{
EmbedBuilder builder = new EmbedBuilder();
builder.WithTitle($"Pong! :ping_pong: - {Context.Client.Latency}ms")
.WithDescription("Ping me again daddy!!")
.WithColor(Color.Magenta);
await ReplyAsync("", false, builder.Build());
}
}
}
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class serverinfo : ModuleBase<SocketCommandContext>
{
[Command("serverinfo")]
public async Task PingAsync()
{
EmbedBuilder builder = new EmbedBuilder();
builder.WithTitle($"Server: {Context.Guild.Name}")
.WithColor(Color.Magenta)
.WithThumbnailUrl(Context.Guild.IconUrl)
.AddInlineField("Owner", $"{Context.Guild.Owner}")
.AddInlineField("Date Created", $"{Context.Guild.CreatedAt}")
.AddInlineField("Members", $"{Context.Guild.MemberCount}")
.AddInlineField("Roles", $"{Context.Guild.Roles.Count}")
.AddInlineField("Text Channels", $"{Context.Guild.TextChannels.Count}")
.AddInlineField("Voice Channels", $"{Context.Guild.VoiceChannels.Count}")
.WithFooter($"{DateTime.Now}");
await ReplyAsync("", false, builder.Build());
}
}
}
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
[Group("bean")]
public class bean : ModuleBase<SocketCommandContext>
{
[Command]
public async Task DefaultBean()
{
EmbedBuilder builder = new EmbedBuilder();
builder.AddField("***BEANED***", "Uh oh! you friccin moron. You just got **BEANED!!!** ")
.WithColor(Color.Green)
.WithThumbnailUrl("https://i.imgur.com/SJ7gNVV.jpg");
await ReplyAsync("", false, builder.Build());
}
[Command]
public async Task TargetBean(SocketGuildUser user)
{
EmbedBuilder builder = new EmbedBuilder();
builder.AddField("***BEANED***", $"Uh oh! you friccin moron. You just got **BEANED!!!** {user.Mention}")
.WithColor(Color.Green)
.WithThumbnailUrl("https://i.imgur.com/SJ7gNVV.jpg");
await ReplyAsync("", false, builder.Build());
}
}
}
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class purge : ModuleBase<SocketCommandContext>
{
[Command("purge")]
[RequireUserPermission(GuildPermission.ManageMessages)]
public async Task PurgeChat(uint amount)
{
var messages = await this.Context.Channel.GetMessagesAsync((int)amount + 1).Flatten();
await this.Context.Channel.DeleteMessagesAsync(messages);
await this.ReplyAsync($"{amount} messages have been purged!");
}
}
}
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
[Group("userinfo")]
public class userinfo : ModuleBase<SocketCommandContext>
{
[Command]
public async Task DefaultUserInfo()
{
EmbedBuilder builder = new EmbedBuilder();
builder.AddField("User info", $"{Context.User.Mention}")
.WithColor(Color.Magenta)
.AddInlineField("Status", $"{Context.User.Status}")
.AddInlineField("Account Created", $"{Context.User.CreatedAt}")
.WithDescription($"For more info, please do n!userinfo {Context.User.Mention}")
.WithThumbnailUrl($"{Context.User.GetAvatarUrl(ImageFormat.Auto)}")
.WithFooter($"{DateTime.Now}");
await ReplyAsync("", false, builder.Build());
}
[Command]
public async Task TargetUserInfo(SocketGuildUser user)
{
EmbedBuilder builder = new EmbedBuilder();
builder.AddField("User info", $"{user.Mention}")
.WithColor(Color.Magenta)
.AddInlineField("Status", $"{user.Status}")
.AddInlineField("Account Created", $"{user.CreatedAt}")
.AddInlineField("Joined at", $"{user.JoinedAt}")
.AddInlineField("Roles", $"{user.Roles.Count}")
.WithThumbnailUrl($"{user.GetAvatarUrl(ImageFormat.Auto)}")
.WithFooter($"{DateTime.Now}");
await ReplyAsync("", false, builder.Build());
}
}
}
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class ban : ModuleBase<SocketCommandContext>
{
[Command("ban")]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.BanMembers)]
public async Task BanMember(IGuildUser user, [Remainder] string reason)
{
if (string.IsNullOrWhiteSpace(reason));
var allBans = await Context.Guild.GetBansAsync();
bool isBanned = allBans.Select(b => b.User).Where(u => u.Username == user.Username).Any();
if (!isBanned)
{
var targetHighest = (user as SocketGuildUser).Hierarchy;
var senderHighest = (Context.User as SocketGuildUser).Hierarchy;
if (targetHighest < senderHighest)
{
await Context.Guild.AddBanAsync(user);
EmbedBuilder builder = new EmbedBuilder();
builder.WithTitle($"Member has been banned! :point_up_2: :weary: :point_up_2: :point_down: :triumph: :point_down: ")
.WithDescription($"{user} was banned, goodbye {user}")
.WithColor(Color.Red)
.WithThumbnailUrl("https://imgur.com/a/Uqs2H")
.WithFooter($"{DateTime.Now}");
await ReplyAsync("", false, builder.Build());
var dmChannel = await user.GetOrCreateDMChannelAsync();
await dmChannel.SendMessageAsync($"You were banned from **{Context.Guild.Name}** for **{reason}**");
}
}
}
}
}
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot.Modules
{
public class nepban : ModuleBase<SocketCommandContext>
{
[Command("nepban"), RequireOwner]
public async Task BanMember(IGuildUser user, [Remainder] string reason)
{
if (string.IsNullOrWhiteSpace(reason)) return;
var allBans = await Context.Guild.GetBansAsync();
bool isBanned = allBans.Select(b => b.User).Where(u => u.Username == user.Username).Any();
if (!isBanned)
{
var targetHighest = (user as SocketGuildUser).Hierarchy;
var senderHighest = (Context.User as SocketGuildUser).Hierarchy;
if (targetHighest < senderHighest)
{
await Context.Guild.AddBanAsync(user);
EmbedBuilder builder = new EmbedBuilder();
builder.WithTitle($"Member has been banned! :point_up_2: :weary: :point_up_2: :point_down: :triumph: :point_down: ")
.WithDescription($"{user} was banned, goodbye {user}")
.WithColor(Color.Red)
.WithThumbnailUrl("https://imgur.com/a/Uqs2H")
.WithFooter($"{DateTime.Now}");
await ReplyAsync("", false, builder.Build());
var dmChannel = await user.GetOrCreateDMChannelAsync();
await dmChannel.SendMessageAsync($"You were banned from **{Context.Guild.Name}** for **{reason}**");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment