You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Justthebasic_voice.py: itdidnotworkforme.
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.
#
# 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())
The text was updated successfully, but these errors were encountered:
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
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.
@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.
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?
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:
Minimal Reproducible Code
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
Checklist
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
The text was updated successfully, but these errors were encountered: