Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Discord ReferenceError:未定义bot_Discord - Fatal编程技术网

Discord ReferenceError:未定义bot

Discord ReferenceError:未定义bot,discord,Discord,这是const或var的一些东西。我认为除非我重新编码它,否则它不会工作。我的问题是: bot.on('ready',()=>{ ^ ReferenceError:未定义bot 在C:\Users\Dylan\Desktop\discord bot\app.js:7:1 在ContextifyScript.Script.runInThisContext(vm.js:50:33) 在Object.runInThisContext(vm.js:139:38) 在模块处编译(Module.js:60

这是const或var的一些东西。我认为除非我重新编码它,否则它不会工作。我的问题是:

bot.on('ready',()=>{
^
ReferenceError:未定义bot
在C:\Users\Dylan\Desktop\discord bot\app.js:7:1
在ContextifyScript.Script.runInThisContext(vm.js:50:33)
在Object.runInThisContext(vm.js:139:38)
在模块处编译(Module.js:607:28)
在Object.Module._extensions..js(Module.js:654:10)
在Module.load(Module.js:556:32)
在tryModuleLoad时(module.js:499:12)
在Function.Module.\u加载(Module.js:491:3)
位于Function.Module.runMain(Module.js:684:10)

启动时(bootstrap_node.js:187:16)
如果需要库,则需要将其更改为
discord.js
才能访问库。
此外,该库不公开名为“Bot”的类,因此需要将其更改为

我猜是
)}应关闭第88行的
ready
事件。
但是我建议您只使用一个ready事件,因此将status和activity方法放在第一个ready事件中,并删除其他方法。另外,如果您已经将bot用户名设置为所需,我会删除该方法,或者检查用户名是否已设置为所需,如果已设置,则不要更改

与所有的
消息
事件相同,只需将一个
消息
事件链接到该事件中的所有if语句。例如:

bot.on('message', message => {
    if (message.content === '!ping') {
        message.channel.send('pong');
    }
    else if (message.content === '!apply') {
        message.channel.send('GOGLE STUFF');
    }
    ...
});

您还需要记住您将变量定义为什么。在第一个
ready
事件中,您使用的是
client.users
,而不是您定义的,
bot
,根据discord.js API文档,没有bot类。 也许你需要的是

const client = new Discord.Client();

我建议您查看应用程序的文档和示例。

您能显示控制台输出吗?请阅读-总结是,这不是向志愿者讲话的理想方式,可能会对获得答案产生反作用。请不要将此添加到您的问题中。