using System;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext;
using Microsoft.Extensions.Logging;
public class Program
{
private DiscordClient discord;
private CommandsNextExtension commands;
private VoiceNextExtension voiceNext;
public static void Main(string[] args)
{
var program = new Program();
program.RunBotAsync().GetAwaiter().GetResult();
}
public async Task RunBotAsync()
{
discord = new DiscordClient(new DiscordConfiguration
{
Token = "TOKEN",
TokenType = TokenType.Bot,
});
discord.Ready += OnClientReady;
commands = discord.UseCommandsNext(new CommandsNextConfiguration
{
EnableDms = false
});
commands.RegisterCommands<Commands>();
commands.SetPrefix("!");
voiceNext = discord.UseVoiceNext();
await discord.ConnectAsync();
await Task.Delay(-1);
}
private async Task OnClientReady(DiscordClient sender, ReadyEventArgs e)
{
Console.WriteLine("Bot is ready.");
await Task.CompletedTask;
}
}
public class Commands : BaseCommandModule
{
[Command("join")]
public async Task Join(CommandContext ctx)
{
var user = ctx.Member;
var voiceChannel = user?.VoiceState?.Channel;
if (voiceChannel == null || voiceChannel.Type != ChannelType.Voice)
{
await ctx.RespondAsync("You must be in a voice channel to use this command.");
return;
}
var voiceNext = ctx.Client.GetVoiceNext();
var connection = await voiceNext.ConnectAsync(voiceChannel);
await ctx.RespondAsync($"Connected to {voiceChannel.Name}");
}
}