【问题标题】:Node packages work locally but not when deployed to Heroku节点包在本地工作,但在部署到 Heroku 时不能
【发布时间】:2020-01-09 21:50:18
【问题描述】:

我实现了一个非常简单的 discord.js 音乐机器人,它使用 node.js 包 ytdl-core 和 opus-script。 bot 永远无法使用部署到 Herkou 时实施的新软件包加入语音频道和流式传输音乐,但与每个命令相关的消息(例如嵌入)仍会发送。

const ytdl = require('ytdl-core');
const streamOptions = { seek: 0, volume: 1}

const Discord = require('discord.js')
require('dotenv-flow').config()
const config = {
    token: process.env.TOKEN,
    owner: process.env.OWNER,
    prefix: process.env.PREFIX
}
const ytdl = require('ytdl-core')
const streamOptions = {
    seek: 0,
    volume: 1
}
const prefix = config.prefix
const client = new Discord.Client()

client.on('ready', () => {
    console.log('ready!')
    console.log(prefix)
    client.user.setActivity("foo", {
        type: "WATCHING"
    })
});

client.on("message", async message => {
    const args = message.content.slice(prefix.length).trim().split(/ +/g)
    const command = args.shift().toLowerCase()
    if (message.author.bot) return
    if (message.content.indexOf(prefix) !== 0) return

    if (command === "play") {
        const link = args[0]
        if (message.channel.id === musicChannel) {
            if (message.member.voiceChannel) {
                if (!link) return message.reply("please enter a YouTube url to play!")
                if (!ytdl.validateURL(`${link}`)) return message.reply("pleae enter a valid YouTube url!")
                message.member.voiceChannel.join().then(connection => {
                        console.log("Successfully connected.");
                        const stream = ytdl(`${link}`, {
                            filter: 'audioonly'
                        })
                        const dispatcher = connection.playStream(stream, streamOptions);
                    })
                    .catch(e => {
                        console.error(e);
                    })
                const embed = new Discord.RichEmbed()
                    .setTitle("__A New Youtube URL Is Playing:__")
                    .setThumbnail(client.user.avatarURL)
                    .addField("Current URL:", `${link}`)
                    .addField("Changed by:", `${message.member.user}`)
                    .setColor("#32a852")
                message.guild.channels.get(musicChannel).send(embed).catch(e => {
                    console.error(e);
                })
            } else {
                message.reply("you must be in a voice channel!")
            }
        } else {
            message.reply(`please use music commands in: <#${musicChannel.toString()}>`)
        }
    }

    if (command === "stop") {
        if (message.channel.id === musicChannel) {
            if (message.guild.voiceConnection) {
                message.guild.voiceConnection.disconnect()
                message.channel.send("successfully disconnected from voice channel!")

            } else {
                message.reply("There is currently no music playing!")
            }
        } else {
            message.reply(`please use music commands in: <#${musicChannel.toString()}>`)
        }

    }

}

});

client.login(process.env.TOKEN);

【问题讨论】:

  • 你确定 Heroku 已经正确安装了 ffmpeg 吗?您可能需要使用build pack

标签: node.js heroku discord.js


【解决方案1】:

尝试通过 github 桌面上传它? (没有 gitignore ,用 node-modules 文件夹上传)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 2015-07-24
    • 1970-01-01
    相关资源
    最近更新 更多