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
    • 0
    • 0
    • 0
    • 0
    • 21
    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

 0 Answer(s)

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: