#Bot crashing when using VoiceNext (Solved)

1 messages · Page 1 of 1 (latest)

glossy sand
#

I can get the bot to join the vc and I'm able to get it to move around in vc, but when using a command to disconnect it from the vc, it completely crashes, and show's this error (posted in picture). Once it does this, the bot will not respond until after I restart it. I have it all set up, in the program, registered the class for commands, and everything. Here's the following code for the commands, I'll send both join and disconnect in case you need it:

Join command:

        public async Task Join(CommandContext ctx)
        {
            var voiceNext = ctx.Client.GetVoiceNext();
            var userChannel = ctx.Member.VoiceState.Channel;
            var connection = await voiceNext.ConnectAsync(userChannel);

            await ctx.RespondAsync($"Successfully joined the channel {connection.TargetChannel.Name} with ID: {connection.TargetChannel.Id}");
        }```

Disconnect command:
```[Command("disconnect")]
public async Task Disconnect(CommandContext ctx)
{
    var voiceNext = ctx.Client.GetVoiceNext();
    var connection = voiceNext.GetConnection(ctx.Guild);
    connection.Disconnect();

    await ctx.RespondAsync($"Successfully left the channel {connection.TargetChannel.Name} with ID: {connection.TargetChannel.Id}");
}```
#

it's also able to identify what voice channel it's in

digital pendant
#

i'm interested in what the stacktrace is

#

and what version are you using?

glossy sand
#

give me a min and I'll get the stack trace

#

so, the try-catch block only reports this:
"Object reference not set to an instance of an object."

which is shown in the picture

digital pendant
glossy sand
#

the entire stack trace, or just where the error occured?

digital pendant
#

the entire stack trace.

glossy sand
#

copied straight from the console:

     [Lightweight Function]    
     [Native to Managed Transition]    
     [Managed to Native Transition]    
     mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args)    Unknown
     DSharpPlus.CommandsNext.dll!DSharpPlus.CommandsNext.Command.ExecuteAsync(DSharpPlus.CommandsNext.CommandContext ctx)    Unknown
     DSharpPlus.CommandsNext.dll!DSharpPlus.CommandsNext.CommandsNextExtension.ExecuteCommandAsync(DSharpPlus.CommandsNext.CommandContext ctx)    Unknown
     DSharpPlus.CommandsNext.dll!DSharpPlus.CommandsNext.Executors.ParallelQueuedCommandExecutor.ExecuteAsync()    Unknown
     [Resuming Async Method]    
     mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(object stateMachine)    Unknown
     mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)    Unknown
     mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)    Unknown
     mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()    Unknown
     mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0()    Unknown
     mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()    Unknown
     System.Threading.Tasks.Extensions.dll!System.Runtime.CompilerServices.ValueTaskAwaiter..cctor.AnonymousMethod__9_0(object state)    Unknown
     System.Threading.Channels.dll!System.Threading.Channels.AsyncOperation<DSharpPlus.CommandsNext.CommandContext>.SetCompletionAndInvokeContinuation()    Unknown
     System.Threading.Channels.dll!System.Threading.Channels.AsyncOperation<DSharpPlus.CommandsNext.CommandContext>.UnsafeQueueSetCompletionAndInvokeContinuation.AnonymousMethod__37_0(object s)    Unknown
     mscorlib.dll!System.Threading.Tasks.Task.InnerInvoke()    Unknown
     mscorlib.dll!System.Threading.Tasks.Task.Execute()    Unknown
     mscorlib.dll!System.Threading.Tasks.Task.ExecutionContextCallback(object obj)    Unknown
     mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)    Unknown
     mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)    Unknown
     mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot)    Unknown
     mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution)    Unknown
     mscorlib.dll!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()    Unknown
     mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()    Unknown
     mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()    Unknown
     [Async Call Stack]    
     [Async] mscorlib.dll!System.Threading.Tasks.Task.Run    Unknown
digital pendant
#

unfortunately this doesn't contain the actual relevant parts of the stack 🙃

#

i don't really know why it's not seeing that part of the stack

#

or even - wait why do you have mscorlib.dll in that stack

#

@glossy sand what target framework are you using and where is your bot running

glossy sand
#

The target framework version is 4.8, and I use Visual Studio 2022 to run my bot

glossy sand
#

I guess the video I watched was outdated then

digital pendant
#

by a few years, yes

glossy sand
#

lol, I'm sorry about that. currently trying to get the latest version installed

glossy sand
#

After updating it to .NET version 9, I can say that it's working now