如何让我的discord bot从YouTube播放音频

时间:2017-08-19 09:41:09

标签: python python-3.x youtube bots discord.py

所以,我的问题是如何将变量url设置为yt之后的某个人类型?例如,!yt [youtbube link]生成url = [youtube link]

这是我目前的代码,感谢任何帮助,谢谢:)

@client.command(pass_context=True)
async def yt(ctx):
    url = 'https://www.youtube.com/watch?v=rPOUewuNKFE'

    author = ctx.message.author
    voice_channel = author.voice_channel
    vc = await client.join_voice_channel(voice_channel)

    player = await vc.create_ytdl_player(url)
    player.start()

3 个答案:

答案 0 :(得分:1)

实际上,这很简单。只需将其作为参数添加到函数中。

@client.command(pass_context=True)
async def yt(ctx, url):

    author = ctx.message.author
    voice_channel = author.voice_channel
    vc = await client.join_voice_channel(voice_channel)

    player = await vc.create_ytdl_player(url)
    player.start()

如果你愿意,你也可以使用标准函数注释(async def yt(ctx, url: str):)指定参数的类型,但它不会非常有用,因为默认情况下它们仍然是作为字符串传递的。< / p>

答案 1 :(得分:0)

我假设你已经知道这一点,但有一些机器人可以为你做到这一点。如果您不这样做,您可以从YouTube给它一个链接,并确保机器人在您的语音通道中。我不确定你是否试图让它在多个语音通道中播放不同的链接。我非常怀疑机器人可以在多个语音通道上播放不同的歌曲,因为它必须与你在语音通道中。

答案 2 :(得分:0)

angular.module('myapp').controller('FirstCont', function ($scope, $http) {

console.log("OUT");

$scope.slctd_lng = 'SDF'
$scope.slct_att = 'SD'

window.initAutocomplete = function () {

    console.log("entered INIT");

    $scope.autocomplete = new google.maps.places.Autocomplete((document.getElementById('autocomplete')),{ types: ['geocode'] });
    $scope.autocomplete.addListener('place_changed', $scocpe.fillInAddress);
}


$scope.fillInAddress = function () {
    var place = $scope.autocomplete.getPlace();

}


$scope.geolocate = function() {

    if (navigator.geolocation) {

        navigator.geolocation.getCurrentPosition(function (position) {

            var geolocation = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
            };

            var circle = new google.maps.Circle({
                center: geolocation,
                radius: position.coords.accuracy
            });

            $scope.autocomplete.setBounds(circle.getBounds());
        });
    }
}});