javascript - 验证码不适用于我的 Discord 机器人
问题描述
我一直在尝试在我的不和谐机器人上制作验证码。我对 JavaScript 完全陌生,我很难理解这些问题。但是,这不是重点。当我在聊天中进行“ri-verification”时,它不起作用。它也不记录任何东西。它只是什么都不做,没有错误。
代码:
const Discord = require('discord.js-12');
const client = new Discord.Client();
const prefix = 'ri-';
const Captcha = require("@haileybot/captcha-generator");
client.once('ready', () => {
console.log('Ready!');
});
let captcha = new Captcha();
console.log(captcha.value);
const path = require("path"),
fs = require("fs")
captcha.PNGStream.pipe(fs.createWriteStream(path.join(__dirname, `${captcha.value}.png`)));
captcha.JPEGStream.pipe(fs.createWriteStream(path.join(__dirname, `${captcha.value}.jpeg`)));
client.on('message', async message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'verification') {
function verifyHuman(msg) {
let captcha = new Captcha();
msg.channel.send(
"**Enter the text shown in the image below:**",
new Discord.MessageAttachment(captcha.JPEGStream, "captcha.jpeg")
);
let collector = msg.channel.createMessageCollector(m => m.author.id === msg.author.id);
collector.on("collect", m => {
if (m.content.toUpperCase() === captcha.value) msg.channel.send("Verified Successfully!");
else msg.channel.send("Failed Verification!");
collector.stop();
});
};
}
});
client.login('');
解决方案
您正在将一个函数放入 if 语句中。很确定你不能那样做。要么将函数放在语句之外,要么将其内容放在 if 语句中。
我将在您的 DM 中进一步解释 :)
推荐阅读
- python-3.x - 在python中生成对应于工作日的日期
- java - 为什么在 for 循环内部声明有效,但在 for 循环外部声明为全局变量无效
- python - CSV 到字节到 DF 以绕过 UnicodeDecodeError:“utf-8”编解码器无法解码位置 0 的字节 0xff:无效的起始字节?
- python - ModuleNotFoundError:没有名为“werkzeug.contrib”的模块(ODOO 12)
- c# - C# HttpWebRequest 参数为空
- javascript - 对于通过 Firebase 运行 CLLocation 函数,您将如何为其构建 index.js 文件?
- xna - 如何在游戏窗口的特定部分绘制游戏
- python - NumPy 和 SciPy 对大矩阵的 SVD 给出不同的答案
- bash - 如何用完整的行替换与不同文件中的另一个字符串匹配的文件中的字符串?
- flutter - 如何使用 cpanel 将 aqueduct 应用程序部署到网络托管计划?