小编Oli*_*ver的帖子

使用 discord.js 和 ytdl-core 播放音频文件

我正在尝试使用 ytdl 和 discord.js 下载并播放从 youtube 获取的音频文件:

        ytdl(url)
            .pipe(fs.createWriteStream('./music/downloads/music.mp3'));

        var voiceChannel = message.member.voiceChannel;
        voiceChannel.join().then(connection => {
            console.log("joined channel");
            const dispatcher = connection.playFile('./music/downloads/music.mp3');
            dispatcher.on("end", end => {
                console.log("left channel");
                voiceChannel.leave();
            });
        }).catch(err => console.log(err));
        isReady = true
Run Code Online (Sandbox Code Playgroud)

我成功地在 ./music/downloads/ 中播放了 mp3 文件,而没有 ytdl 部分 ( ytdl(url).pipe(fs.createWriteStream('./music/downloads/music.mp3'));)。但是当那部分在代码中时,机器人就会加入然后离开。

这是带有 ytdl 部分的输出:

Bot has started, with 107 users, in 43 channels of 3 guilds.
joined channel
left channel
Run Code Online (Sandbox Code Playgroud)

这是没有 ytdl 部分的输出:

Bot has started, with 107 users, in 43 channels of 3 guilds. …
Run Code Online (Sandbox Code Playgroud)

javascript node.js discord.js

2
推荐指数
1
解决办法
2万
查看次数

将十六进制字符串转换为base64

byte[] ba = Encoding.Default.GetBytes(input);
var hexString = BitConverter.ToString(ba);
hexString = hexString.Replace("-", "");
Console.WriteLine("Or: " + hexString + " in hexadecimal");
Run Code Online (Sandbox Code Playgroud)

所以我明白了,现在我将如何转换hexString为base64字符串?
我尝试了这个,得到了错误:

无法从字符串转换为字节[]

如果该解决方案对其他任何人都有效,那我在做什么错呢?

编辑:

 var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
 return System.Convert.ToBase64String(plainTextBytes);
Run Code Online (Sandbox Code Playgroud)

我尝试了这一点,但是它在第一行返回“无法将类型'byte []'隐式转换为'string'”,然后返回“参数1:无法从'string'转换为'byte []'”。

c# base64 hex

-4
推荐指数
1
解决办法
5481
查看次数

标签 统计

base64 ×1

c# ×1

discord.js ×1

hex ×1

javascript ×1

node.js ×1