【问题标题】:My bot throws no errors, but can't seem to connect to Discord我的机器人没有抛出任何错误,但似乎无法连接到 Discord
【发布时间】:2020-05-13 09:43:23
【问题描述】:

我的 auth.json 看起来像这样:

{
    "token" : "[CENSORED]"
}

我的机器人代码如下所示:

//recognise dependancies
var auth = require("./auth.json");
var Discord = require("discord.io");
var bot = new Discord.Client({
    token: auth.token,
    autorun: true
});

//log connection message

bot.on("ready", function(){
    console.log('Logged in as ' + bot.username + ' with an ID of ' + bot.id + '')
});

...(Unrelated code)...

//reconnecting after being disconnected

bot.on('disconnect', function(){
    console.log("Disconnected from Discord. Attempting to reconnect...")
    bot.connect();
})

注意最后的断开功能

这就是我的 package.json 的样子:

{
  "name": "itachi",
  "version": "1.0.0",
  "description": "",
  "main": "Itachi.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "Alibi",
  "license": "ISC",
  "dependencies": {
    "discord.io": "^2.5.3"
  }
}

当我尝试运行 itachi.js 文件时,我没有收到任何错误,但它从未连接,它会发送断开连接消息,然后停止

C:\Users\[ME]\Desktop\Itachi>node itachi.js
Disconnected from Discord. Attempting to reconnect...

C:\Users\[ME]\Desktop\Itachi>

我不知道该怎么做才能使其连接,我认为可能是由于互联网速度慢,但事实并非如此。我确保我的令牌是正确的。它只是无法连接,我不明白为什么。

【问题讨论】:

    标签: javascript node.js windows discord discord.io


    【解决方案1】:

    我发现了一些东西!我遇到了完全相同的问题,但是当我改用这个包时,在 npm 上找到了:

    discord.io-gateway6

    效果很好。听起来像普通包 discord.io 只是过时了,并且使用旧的 API 来处理不和谐 - 而 gateway6 版本

    【讨论】:

      猜你喜欢
      • 2020-09-23
      • 2021-04-21
      • 2020-12-08
      • 2021-02-19
      • 2022-06-12
      • 2020-08-06
      • 2020-04-14
      • 2022-11-27
      • 1970-01-01
      相关资源
      最近更新 更多