Javascript Discord Bot是否可以将DM发送给特定人员?

时间:2020-07-14 22:45:02

标签: javascript discord bots

我正在尝试创建一个允许用户发送消息并从机器人接收DM的系统。那部分工作正常。但是,我也希望该机器人在发生这种情况时向自己发送一条消息。每当我尝试让它向我发送消息时,它总是会出现错误。

public static File decryptDataFileBufferedCipherInputStream (File inputFile, File outputFile, File keyFile, String correlationId) throws
            IOException, NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, InvalidKeyException
    {
        Security.addProvider(new BouncyCastleProvider());
        String key = new String(Files.readAllBytes(keyFile.toPath())).trim();
        byte[] salt = new byte[8];
        byte[] salted = new byte[8]; // text SALTED__
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        try (FileInputStream in = new FileInputStream(inputFile.toPath().toString()); // i don't care about the path as all is lokal
             CipherInputStream cipherInputStream = new CipherInputStream(in, cipher);
             FileOutputStream out = new FileOutputStream(outputFile.toPath().toString())) // i don't care about the path as all is lokal
        {
            byte[] buffer = new byte[8192];
            in.read(salted);
            in.read(salt);
            SecretKeyFactory fact = SecretKeyFactory.getInstance("PBEWITHMD5AND256BITAES-CBC-OPENSSL", "BC");
            SecretKey secretKey = fact.generateSecret(new PBEKeySpec(key.toCharArray(), salt, 100));
            System.out.println("secretKey length: " + secretKey.getEncoded().length + " data: " + bytesToHex(secretKey.getEncoded()));
            cipher.init(Cipher.DECRYPT_MODE, secretKey);
            int nread;
            while ((nread = cipherInputStream.read(buffer)) > 0) {
                out.write(buffer, 0, nread);
            }
            out.flush();
        }
        if (outputFile.exists()) {
            return outputFile;
        } else {
            return null;
        }
    }

在显示message.ageekdude.send的部分,我正在尝试将其发送给我。另外,在显示message.author的部分,您能告诉我如何用用户名代替用户ID吗?

1 个答案:

答案 0 :(得分:0)

if (message.toString().toLowerCase().includes('support')) {
    message.author.send('Your assistance ticket has been created. Please wait for a DM from ageekdude.');
    const ageekdude = client.users.cache.get('PASTE YOUR USER ID HERE');
    if (ageekdude) ageekdude.send(message.author + ' has requested an assistance ticket.')
}

这将尝试在所有bot用户列表中找到您,然后向您发送消息,
我希望这能解决您的问题!

相关问题