discord-php / DiscordPHP

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

Error 401 #238

Closed parapauk closed 7 years ago

parapauk commented 7 years ago

Hi,

I have set it up as per the instructions and registered a bot with discord. I put the bot's auth token into the bot.php file as per the documentation, but when it runs I get the following:

PHP Fatal error: Uncaught exception 'Discord\Exceptions\DiscordRequestFailedException' with message 'Erorr code 401: There was an error processing the request. UNAUTHORIZED - {"code": 0, "message": "401: Unauthorized"} - users/@me' in /root/vendor/team-reflex/discord-php/src/Discord/Helpers/Guzzle.php:212

Can anyone advise please?

benharri commented 7 years ago

Looks like your token is invalid or you have it registered wrong. Double check it and make sure it doesn't include "Bot " at the beginning

parapauk commented 7 years ago

Hi,

this is the code within my bot file:

`<?php

include DIR.'/vendor/autoload.php';

$discord = new \Discord\Discord([ 'token' => 'MzA5NDQwNjc2ODc2MjU1MjMz.C-zIhQ._pdgWDDO4eOyzj5lIVjT2_lnLwg', ]);

$discord->on('ready', function ($discord) { echo "Bot is ready.", PHP_EOL;

// Listen for events here
$discord->on('message', function ($message) {
    echo "Recieved a message from {$message->author->username}: {$message->content}", PHP_EOL;
});

});

$discord->run(); `

It's definitely the same token as shown on the https://discordapp.com/developers/applications/me/ page

pazuzu156 commented 7 years ago

Why are you sharing your bot token?

parapauk commented 7 years ago

Thanks, pazuzu for the assistance! Oh, wait. It's an old key.

pazuzu156 commented 7 years ago

It's a serous question. You shouldn't share tokens.

parapauk commented 7 years ago

Sorry which part of my very serious answer didnt you get?

shibdib commented 7 years ago

Tokens in this case don't mean jack, simple to delete it or refresh it once he gets his answer. Provide some help to the actual issue or don't comment at all