So I'm building a bot that is meant to assign a role when the user dms the bot "!Accept" the problem is when I attempt to test this I receive this error
A MessageReceived handler has thrown an unhandled exception.: System.NullReferenceException: Object reference not set to an instance of an object. at Discord.Commands.SocketCommandContext..ctor(DiscordSocketClient client, SocketUserMessage msg) at UBot_CodeV2.Program.d__9.MoveNext() in C:\Users\sarah\source\repos\UBot_CodeV2\UBot_CodeV2\Program.cs:line 70 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Discord.EventExtensions.d__1`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Discord.WebSocket.DiscordSocketClient.d__132.MoveNext() Object reference not set to an instance of an object.
[Command("Accept")]
public async Task Accepted()
{
var role = Context.Guild.GetRole(780162818729050114);
if ((Context.Guild.GetUser(Context.User.Id).Roles.Contains(role))) return;
await ((SocketGuildUser)Context.User).AddRoleAsync(role);
await Context.User.SendMessageAsync("Welcome! Your next step is to open a ticket with !ticket open Verification");
}
This is the code I have for the task curently