【发布时间】:2021-03-20 08:00:53
【问题描述】:
我正在为特定应用程序制作 Discord 机器人,该应用程序需要在机器人收到 POST 调用时更改用户的语音通道,但我正在努力正确调用 Discord 部分。 现在我可以通过使用此代码的命令来做到这一点
bot.on("message", async (message) => {
let messageArray = message.content.split(" ");
let command = messageArray[0];
if (message.author.bot) return;
if (message.channel.type === "dm") return;
if (!command.startsWith(prefix)) return;
if (command === `${prefix}tochannel`) {
let channelID = messageArray[1];
if (!channelID) return message.channel.send("Please specify the channel ID!");
message.member.voice.setChannel(channelID);
}
});
我在 Express 中还有一些代码可以调用带有两个文本字段的表单,仅用于测试
const app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.get("/", function (req, res) {
res.sendFile(__dirname + "/index.html");
});
app.post("/", function (req, res) {
var toChannel = Number(req.body.channelID);
var userID = Number(req.body.userID);
console.log(channelID);
console.log(userID);
res.send("Channel ID: " + channelID + " >> " + "User ID: " + userID);
});
我最大的噩梦是:如何让这两个宇宙相互交谈?
【问题讨论】:
标签: node.js express discord discord.js