【问题标题】:Discord bot won't start, type/namespace nameDiscord bot 无法启动,输入/命名空间名称
【发布时间】:2018-10-11 22:51:12
【问题描述】:

基本上,我为我的第一个不和谐机器人写出了代码(可能是错误的)。基本的,只是登录,不会运行。它给了我关于

的错误

类型或命名空间名称 'DiscordClient 可能或无法找到

与“LogMessageEventArgs”重复相同

程序代码:

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

namespace DiscordBot
{
   class Program
{
        static void Main(string[] args)
        {
            MyBot bot = MyBot();
        }
    }
}

MyBot 代码:

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

namespace DiscordBot
{
    class MyBot
    {
        DiscordClient discord;

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

        discord.ExecuteAndWait(async () =>
        {
            await discord.Connect("the token");
        });
    }

        private void Log (object sender, LogMessageEventArgs e)
        {
            Console.WriteLine(e.Message);
        }
    }
}

【问题讨论】:

  • 你在哪里上课 DiscordClient ?
  • @Stephu 所说的是您的声明: DiscordClient discord;要求您指定类/对象/类型:DiscordClient
  • @DaniDev 我该怎么做?很抱歉问这个问题,但我在网上关注了一百万个教程,在数小时内撞到这个问题后我有点迷失了。

标签: c# .net discord discord.net


【解决方案1】:

“Discord.Net”包中不存在DiscordClient 类型,因此您要么必须自己创建它,要么(通常)使用 NuGet 包附带的预定义类型之一。请参阅 this 以获得良好的入门指南。

【讨论】:

  • 谢谢,查看指南后很快就可以使用了!
猜你喜欢
  • 2021-11-10
  • 2017-05-21
  • 2017-12-29
  • 2017-07-08
  • 2020-11-18
  • 1970-01-01
  • 2018-10-31
  • 1970-01-01
  • 2015-01-23
相关资源
最近更新 更多