discord-php / DiscordPHP

An API to interact with the popular messaging app Discord
MIT License
998 stars 237 forks source link

VoiceClient not working for me #904

Open Dark-night45 opened 2 years ago

Dark-night45 commented 2 years ago

Environment

Description I have problem with play music from file in voice when i run command, bot joined to voice but no sound. in console i don't get any error. also i use debug code but no error. i have all requirements too but file not played in voice.

Code :

    $voiceChannel = $message->guild->channels->get('id', '922503052420849684');
    $discord->joinVoiceChannel($voiceChannel, false, false)->then(function (VoiceClient $vc) {
      echo "Music Played";
      $vc->playFile('gg.mp3'); //the file is in code folder and i try __DIR__ too
    });

Edit : Update discordphp version

key2peace commented 2 years ago

which operating system are you using for your bot?

Dark-night45 commented 2 years ago

Windows 10 x64

key2peace commented 1 year ago

can you try again with current dev-master?

Dark-night45 commented 1 year ago

I use normal master but now i updated it(v7.3.3) but my music file not played also i tested dev-master, but with dev-master i can't run the bot and this is the error message i got :

PHP Fatal error:  Uncaught Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException: The option "pmChannels" does not exist. Defined options are: "cacheInterface", "cacheSweep", "disabledEvents", "dnsConfig", "intents", "loadAllMembers", "logger", "loop", "retrieveBans", "shardCount", "shardId", "socket_options", "storeMessages", "token". in C:\xampp\htdocs\back now\bot\vendor\symfony\options-resolver\OptionsResolver.php:871
Stack trace:
#0 C:\xampp\htdocs\back now\bot\vendor\team-reflex\discord-php\src\Discord\Discord.php(1422): Symfony\Component\OptionsResolver\OptionsResolver->resolve()
#1 C:\xampp\htdocs\back now\bot\vendor\team-reflex\discord-php\src\Discord\Discord.php(362): Discord\Discord->resolveOptions()
#2 C:\xampp\htdocs\back now\bot\index.php(44): Discord\Discord->__construct()
#3 {main}
  thrown in C:\xampp\htdocs\back now\bot\vendor\symfony\options-resolver\OptionsResolver.php on line 871
SQKo commented 1 year ago

but with dev-master i can't run the bot and this is the error message i got :

Remove 'pmChannels' from your Discord options, it is no longer available in v10

$discord = new Discord([
    'pmChannels' => ... // remove this
]);
Dark-night45 commented 1 year ago

My bot run successfully But no command worked and no error was displayed in the console

key2peace commented 1 year ago

is your bot verified? is the command a message one without mention or through slash? do you have message_content intent enabled?

Dark-night45 commented 1 year ago

My bot not verified, i don't have any slash command and message_content is enabled

key2peace commented 1 year ago

is it also enabled in the intents defined in the options for $discord = new Discord()? (See #905)

Dark-night45 commented 1 year ago

i see the following issue, but if my bot return empty, then why functions like join voice not working

key2peace commented 1 year ago

I don't have any such issues as you described above, also, in regards to joining a voice channel, nothing really changed, so this should simply work, even on your 7.3.3, show me your discord construct (without the token)

Dark-night45 commented 1 year ago
include __DIR__ . '/vendor/autoload.php';
require_once('secret.php');
$GLOBALS['prefix'] = '.';
$token = get_token();

$discord = new Discord([
  'token' => $token,
  'loadAllMembers' => false,
  'storeMessages' => false,
  // 'pmChannels' => false
  // 'dnsConfig' => '8.8.8.8'
]);

$discord->on('ready', function(Discord $discord){
  echo "Bot is online";
});
$discord->on('ready', function($discord) {
  $activity = $discord->factory(Activity::class, [
    'name' => 'KC',
    'type' => Activity::TYPE_COMPETING
  ]);
  $discord->updatePresence($activity, false, "idle", false);
});

$discord->on('error', function ($e) {
  echo emit('udp-error', [$e]);
});
$discord->run();
bariscodefxy commented 1 year ago

My bot run successfully But no command worked and no error was displayed in the console

@Dark-night45 Hello, I know it's late but I updated my Hiro-Bot and commands were not worked for me too. I fixed with adding intent, 'Intents::MESSAGE_CONTENT'.

Example from my bot:

$bot = new Hiro([
    'token' => $_ENV['TOKEN'],
    'prefix' => $_ENV['PREFIX'],
    'shardId' => $shard_id,
    'shardCount' => $shard_count,
    'caseInsensitiveCommands' => true,
    'loadAllMembers' => true,
    'intents' => Intents::getDefaultIntents() | Intents::GUILD_MEMBERS | Intents::MESSAGE_CONTENT
]);

I'm seeing you're not using intents so you can fix that with adding this to array:

    'intents' => Intents::getDefaultIntents() | Intents::GUILD_MEMBERS | Intents::MESSAGE_CONTENT

If you don't wanna to use GUILD_MEMBERS intent,

    'intents' => Intents::getDefaultIntents() | Intents::MESSAGE_CONTENT

this is works too.

Steveb-p commented 8 months ago

Had the same issue. Promise seemed stuck in an unresolved state after UDP connection was established (event listeners for the voice status change never fired). Updating the library to current dev-master resolved the issue.

Seems like those events are no longer emitted on version pre 10.0-RC.