【发布时间】:2021-11-17 10:35:57
【问题描述】:
我一直在用 Python 为 Discord 编写代码,但我想切换到 JS,因为还有更多。我遇到了一些麻烦,机器人没有加入或离开命令。所以我创造了一个。我可以让加入工作,但机器人不能离开。
const util = require("../util");
var arr = []
module.exports = {
name: "join",
aliases: ["j"],
exec: async (msg, args) => {
const { music } = msg.guild;
if (!msg.member.voice.channel)
return msg.channel.send(`:x: You need to be in a voice channel to run this command!`);
if (msg.guild.me.voice.channel && !msg.guild.me.voice.channel.equals(msg.member.voice.channel))
return msg.channel.send(`:thumbsup: **I've left** ${msg.guild.me.voice.channel} **and joining** ${msg.member.voice.channel}!`);
await music.join(msg.member.voice.channel);
const missingPerms = util.missingPerms(msg.guild.me.permissionsIn(msg.member.voice.channel), ["CONNECT", "SPEAK"]);
if ((!music.player || !music.player.playing) && missingPerms.length)
return msg.channel.send(`Hmm :thinking: I am unable to join you're voice chat! I am missing the permission: ${missingPerms.map(x => `\`${x}\``).join(", ")}. Do I have access to this voice chat?`);
else {
await music.join(msg.member.voice.channel);
}
}
}
如何让机器人移动和离开?
【问题讨论】:
-
其中哪一部分没有按预期工作?有什么错误吗?
-
嘿@MrMythical 感谢您的回复。在 python 中,我可以做 voice.disconnect() 但我不知道如何在 JS 中断开与语音的连接。在第 10 行,我要么希望机器人断开连接并重新加入新频道,要么喜欢 music.move_to() 之类的东西。谢谢
标签: node.js discord discord.js