Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic_voice.py example does not work (on macOs and on Ubuntu) #9070

Open
3 tasks done
mgiugliano opened this issue Nov 16, 2022 · 4 comments
Open
3 tasks done

basic_voice.py example does not work (on macOs and on Ubuntu) #9070

mgiugliano opened this issue Nov 16, 2022 · 4 comments
Labels
no repro Cannot be reproduced.

Comments

@mgiugliano
Copy link

mgiugliano commented Nov 16, 2022

Summary

BOT connects to a voice channel but no sound is played

Reproduction Steps

Simply launching the sample code basic_voice.py and exploring all (BOT) commands made it clear that:

  • the BOT joins the (voice) channel, whose ID is passed to the !join command
  • no sound is played
  • YouTube link/stream do not work

Minimal Reproducible Code

Just the basic_voice.py: it did not work for me.

Expected Results

I would have expected a *.mp3 or *.wav file to be played in the voice chat.

Actual Results

BOT joins the voice channel but does not play any sound (YouTube, files, stream, etc.)

Intents

intents = discord.Intents.default()

System Information

  • Python v3.10.8-final
  • discord.py v2.0.1-final
  • aiohttp v3.8.3
  • system info: Darwin 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:54 PDT 2022; root:xnu-8792.41.9~2/RELEASE_X86_64

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

After several days of struggle, I finally converged on a minimal and working example - below.

As I am not fluent in Discord.py, I would like to understand why the sample code provided by the Author of the library does not work and my "patchwork" shy attempt does.

https://gist.github.com/mgiugliano/25428789c00b8ba1c1073c3e3f2f8294

#
# Minimal code for an audio file player BOT in a voice channel
#   
# Entirely based on the example from Rapptz (that was NOT working for me)
# https://github.com/Rapptz/discord.py/blob/master/examples/basic_voice.py
#
# Nov 15 2022

import asyncio
import discord
from discord.ext import commands

from config_private import *        # Import private credentials (prefs.py)


ffmpeg_options = {              # type > ffmpeg --help, to list options
    'options': '-vn',           # disable video
}


class AudioTest(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def testme(self, ctx):
        """USAGE  !testme (joins the voice chan specified by CHANNEL, and plays a file)"""

        # This is the filename to play
        filename = './a.mp3'        # it works with *.wav files too

        channel = await self.bot.fetch_channel(CHANNEL)

        vc = await channel.connect()
        await ctx.send(f'Connected!')

        vc.play(discord.FFmpegPCMAudio(filename))
        vc.source = discord.PCMVolumeTransformer(vc.source)
        vc.source.volume = 0.5


        while vc.is_playing():
            await ctx.send(f'Still playing...')
            await asyncio.sleep(0.5)

        await vc.disconnect(force=True) 
        await ctx.send(f'Disconnected!')




intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(
    command_prefix=commands.when_mentioned_or("!"),
    description='Minimal audio-file player bot example',
    intents=intents,
)


@bot.event
async def on_ready():
    print(f'Logged in as {bot.user} (ID: {bot.user.id})')
    print('------')


async def main():
    async with bot:
        await bot.add_cog(AudioTest(bot))
        await bot.start(TOKEN)


asyncio.run(main())
@mgiugliano mgiugliano added the unconfirmed bug A bug report that needs triaging label Nov 16, 2022
@Rapptz Rapptz added no repro Cannot be reproduced. and removed unconfirmed bug A bug report that needs triaging labels Nov 16, 2022
@Subcode
Copy link

Subcode commented Nov 22, 2022

It doesnt work for me either.
Python 3.10.6
discord.py version 2.1.0
OS: ubuntu 22.04

Just running the example works, it joins the server.
The help command also works, but /join etc do nothing. (i changed the command prefix to /. using ! also does not work)

On discord it returns: The application did not respond

@uaimio
Copy link

uaimio commented Dec 12, 2022

I've found the inconsistency related to this issue in lines 85 and 95 of the example: voice_client.play(...) is called before the variable player has been instantiated because the main loop calls YTDLSource.from_url after the ctx.typing() closure.

EDIT: After a couple of minutes it seems to work, there is an undefined behaviour in some way.

@mgiugliano
Copy link
Author

@Rapptz May I ask you to explain why "no repro" tag is used in this case? It seems other people reported similar problems I did. Thank you for your work.

@imayhaveborkedit
Copy link
Contributor

This issue is a bit old, but the voice connection code for the library has been rewritten. If you're still having this issue, do you mind seeing if it still happens on the latest commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no repro Cannot be reproduced.
Projects
None yet
Development

No branches or pull requests

5 participants