Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Getting Exception Error While Building a Discord Bot in Visual Studio

    • 0
    • 0
    • 0
    • 3
    • 0
    • 0
    • 0
    • 610
    Answer it

    I am trying to build a discord bot in visual studio and while executing the code I am getting few exceptions errors. Pelase help me to resolve that. Below is my line by line code, please check and help me to run this code perfectly.



    using Discord;
    using Discord.Commands;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace A2
    {
        class MyBot
        {
            DiscordClient discord;

            public MyBot()
            {
                discord = new DiscordClient(x =>
              {
                  x.LogLevel = LogSeverity.Info;

                  x.LogHandler = Log;
              });
                discord.UsingCommands(x =>         
                {
                    x.PrefixChar = '~';
                    x.AllowMentionPrefix = true;

                });

                var commands = discord.GetService<CommandService>();

                commands.CreateCommand("Hello")
                    .Do (async (e) =>
                    {
                       await e.Channel.SendMessage("Hey");
                    });

                discord.ExecuteAndWait(async () =>
                {
                    await discord.Connect("My discord token", TokenType.Bot);
                });
            }
          private void Log(object sender, LogMessageEventArgs e)
            {
                Console.WriteLine(e.Message);
            }  
        }
    }

     Errors:
    cs1002     ; expected                   line 3

    cs1001     identifier expected    line 17

    cs1002     ; expected                   line 17

    cs1519    invalid token '(' in class, struct, or interface member declaration     line 20

    cs1022    type or namespace definition, or end of file expected     line 23

 3 Answer(s)

  • Hello @abishek.kumar 
    I belive I am currently using the latest version of visual studio, I will check for other updates.
    The discord bot is exactly as I left it.
    If the code turned up nothing ut might be that I did not include the discord token.
    I do hope you can help me with this.
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: