none
AddModulesAsync show error CS7036, .Net core 2.1 RRS feed

  • Question

  • I was making a discord bot by two tutorials and in both I had problem with AddModuleAsync. I am still learning C# but I was looking for fixes and nothing helped.

    Code:

    using System;
    using System.IO;
    using System.Reflection;
    using System.Threading.Tasks;
    using Discord;
    using Discord.Commands;
    using Discord.WebSocket;

    namespace NewDCbot
    {
        class Program
        {
            private DiscordSocketClient Client;
            private CommandService Commands;

            static void Main(string[] args)
            => new Program().MainAsync().GetAwaiter().GetResult();

            private async Task MainAsync()
            {
                Client = new DiscordSocketClient(new DiscordSocketConfig
                {
                    LogLevel = LogSeverity.Debug
                });

                Commands = new CommandService(new CommandServiceConfig
                {
                    CaseSensitiveCommands = true,
                    DefaultRunMode = RunMode.Async,
                    LogLevel = LogSeverity.Debug
                });

                Client.MessageReceived += Client_MessageReceived;
                await Commands.AddModulesAsync(Assembly.GetEntryAssembly());

                Client.Ready += Client_Ready;
                Client.Log += Client_Log;

                string Token = "";
                using (var Stream = new FileStream((Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).Replace(@"bin\Debug\netcoreapp2.1", @"Token\Token.txt"), FileMode.Open, FileAccess.Read))
                using (var ReadToken = new StreamReader(Stream))
                {
                    Token = ReadToken.ReadToEnd();
                }

                await Client.LoginAsync(TokenType.Bot, Token);
                await Client.StartAsync();

                await Task.Delay(-1);
            }

            private async Task Client_Log(LogMessage Message)
            {
                Console.WriteLine($"{DateTime.Now} at {Message.Source}] {Message.Message}");
            }

            private async Task Client_Ready()
            {
                await Client.SetGameAsync("Spamming letters");
            }

            private async Task Client_MessageReceived(SocketMessage arg)
            {
                //Commands
            }
        }
    }

    I would like to run that bot.

                
    Saturday, March 23, 2019 10:23 AM

All replies

  • Hello,

    To learn properly sometimes a good working example is best as per the following GitHub repository. Here is a lesson on making your first bot.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Saturday, March 23, 2019 2:41 PM
    Moderator