dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
717 stars 163 forks source link

voice_client is_playing throws error if self._player is not defined #212

Closed SinanAkkoyun closed 2 years ago

SinanAkkoyun commented 2 years ago

Summary

Idk python, but I needed to fix an error (i think it was unintended but idk py)

Reproduction Steps

Just follow the code and install discord.py at rebase branch

Code

import discord
import asyncio

class MyClient(discord.Client):
  async def on_ready(self):
    print('Logged on as', self.user)

  async def on_message(self, message):
    # don't respond to ourselves
    if message.author == self.user:
      return

    if message.content == 'voice':
      FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn', 'executable': 'C:/ffmpeg/bin/ffmpeg.exe'}
      channel = message.author.voice.channel
      vc = await channel.connect()
      source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio('rickroll.mp3', **FFMPEG_OPTIONS))

      vc.play(source, after=lambda e: print(f'Player error: {e}') if e else None)

      await message.send("**TEST TEST TEST TEST TEST**")
      await message.voice_client.disconnect()

client = MyClient()
client.run('token')

Expected Results

should work

Actual Results

doesnt:

\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\voice_client.py", line 260, in is_playing
    if(self._player.is_playing()):
AttributeError: '_MissingSentinel' object has no attribute 'is_playing'

System Information

well, I installed the rebase by cloning it and then running python3 -m pip install .

python -m discord -v C:\Python310\python.exe: No module named discord.main; 'discord' is a package and cannot be directly executed

Checklist

Additional Information

voice_client.py line 256 my fix:

def is_playing(self) -> bool:
        """Indicates if we're currently playing audio."""
        playing = self._player is not None
        if(self._player is not None):
          if(getattr(self, 'get_playing()', self._player)):
            return self._player.is_playing()
        return False

I get another error then but at least this one is gone Its also very bad py

TheOnlyWayUp commented 2 years ago

Its also very bad py

💀

I would suggest using discord.ext.commands.Bot instead of subclassing discord.Client, it has better everything, you can view the differences here and here.

I'll try your code and will reply with a CR/CNR, will be using fba0cc61199ebacfe2d8dece68b5c21ee4f5c41b.

I get another error then but at least this one is gone

If it's related to this issue in any way, please include a full traceback.

voice_client.py line 256 my fix:

Consider making a pull request if you're sure it's functional.

SinanAkkoyun commented 2 years ago

Thank you so much!!!

Here is the full traceback:

Traceback (most recent call last):
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 334, in _run_event
    await coro(*args, **kwargs)
  File "X:\py\main.py", line 29, in on_message
    vc.play(source, after=lambda e: print(f'Player error: {e}') if e else None)
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\voice_client.py", line 849, in play
    return self.player.play(source, after=after)
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\voice_client.py", line 314, in play
    self._player = AudioPlayer(source, self, after=after)
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\player.py", line 630, in __init__
    self._connected: threading.Event = client._connected
AttributeError: 'Player' object has no attribute '_connected'

Also, ext is not defined for me, do I need to install rebase somehow differently/what is the correct way?

Hm, if you'd test my sample code anyways I would love to know if voice playback and rec does work for you! I am a py beginner and have the suspicion that I badly messed somewhere up when setting everything up

Thanks again :)

SinanAkkoyun commented 2 years ago

I tried the music bot example and this happened:

Traceback (most recent call last):
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 334, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 1024, in on_message
    await self.process_commands(message)
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 1021, in process_commands
    await self.invoke(ctx)
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 984, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 886, in invoke
    await self.prepare(ctx)
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 822, in prepare
    await self.call_before_hooks(ctx)
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 760, in call_before_hooks
    await self._before_invoke(instance, ctx)  # type: ignore
  File "X:\py\musicbot.py", line 123, in ensure_voice
    elif ctx.voice_client.is_playing():
AttributeError: 'VoiceClient' object has no attribute 'is_playing'
SinanAkkoyun commented 2 years ago

When I set the self._connected to a new threading.Event() and call set() immediately after that in init in player.py, I get this error:

Traceback (most recent call last):
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\player.py", line 674, in run
    self._do_run()
  File "C:\Users\x\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\player.py", line 642, in _do_run
    play_audio = self.client.send_audio_packet
AttributeError: 'Player' object has no attribute 'send_audio_packet'
dolfies commented 2 years ago

I might've slightly broken voice stuff while working on voice receive. Oops!

SinanAkkoyun commented 2 years ago

I might've slightly broken voice stuff while working on voice receive. Oops!

Oh, well :D I was almost going crazy thinking I messed up Is there a way for me to get a working version of your nice lib running or do I have to wait? :)

TheOnlyWayUp commented 2 years ago

Is there a way for me to get a working version of your nice lib running or do I have to wait? :)

Your best bet is to watch this repository (near the star button, top right) to receive notifications (email) on repo updates (I think).

Also, ext is not defined for me, do I need to install rebase somehow differently/what is the correct way?

That's... peculiar. I usually git clone --single-branch -b rebase https://github.com/dolfies/discord.py-self, and do mv discord.py-self/discord . && rm -r discord.py-self. That way, I have a copy of discord.py-self as a folder, and if I need to make any changes, I can do so without too much hassle (going into site-packages).

dolfies commented 2 years ago

Fixed in latest commit.

SinanAkkoyun commented 2 years ago

no way, I will try it, thank you so much!!!!!!!!!

SinanAkkoyun commented 2 years ago

Hi, now I get this error : Player error: send_audio_packet() got an unexpected keyword argument 'encode'

omnituensaeternum commented 1 year ago

@SinanAkkoyun Did you ever get this working and if so could you share with me how you did?