Discord.js不发送消息(无错误)
我刚刚开始使用discord.js为我的discord服务器创建一个bot。我正试图使机器人发送消息,但它就是不这样做。我甚至没有任何错误。 下面是一段不起作用的代码片段:Discord.js不发送消息(无错误),discord.js,Discord.js,我刚刚开始使用discord.js为我的discord服务器创建一个bot。我正试图使机器人发送消息,但它就是不这样做。我甚至没有任何错误。 下面是一段不起作用的代码片段: bot.on('voiceStateUpdate', (oldMember, newMember) => { let newUserChannel = newMember.voiceChannel let oldUserChannel = oldMember.voiceChannel if(o
bot.on('voiceStateUpdate', (oldMember, newMember) => {
let newUserChannel = newMember.voiceChannel
let oldUserChannel = oldMember.voiceChannel
if(oldUserChannel === undefined && newUserChannel !== undefined) {
// User Joins a voice channel
console.log("Join");
if(newMember = manu) {
console.log("kyllä")
bot.on('message', msg => {
msg.channel.send("Manu, oletko käynyt parturissa? \n Kirjoita vastauksesi numero. \n 1. Olen \n 2. En");
})
bot.on('message', msg => {
if(msg.content === "2") {
msg.channel.send("Ja parturin kautta takasin");
}
else if(msg.content === "1") {
msg.channel.send("Hyvvö");
}
else {
msg.channel.send("Puhu suomea");
}
})
}
}
else if(newUserChannel === undefined){
// User leaves a voice channel
console.log("Leave");
}
})
如果你能理解文本部分的语言,请注意这个机器人只是为了好玩:D
我做错了什么?您编写了
if(newMember=manu){
。您需要使用==
或=
来比较两个值。使用=
仅为变量赋值。我认为问题是:您将bot.on放在bot.on中。您可以做的是将第二个bot.on与另一个bot.on下面的消息放在一起,它应该可以解决您的问题。最好使用消息c我认为它不会工作,但我知道它已经很晚了,但是没有做bot.on使用消息采集器你现在有错误吗?或者其他组件比以前有错误吗?我看不到任何更改。没有错误,也没有更早。早些时候我试着为if语句创建控制台日志,它工作了。但是出于某种原因n bot不会在discord上发送消息。它是discord ID的变量,我已经检查过它是否有效。使用伪值测试,如if(newMember==“YOURID”)
没有更改。代码应该检测何时有人加入语音频道(确实如此)然后检查加入的用户是否是特定用户,如果是,它会在文本频道上询问问题,然后根据答案执行操作。我尝试使用console.log(“它工作”)
作为用户识别部分。它记录了它,所以它工作。它只是不向discord发送消息。其他一切似乎都工作正常。