Giter Site home page Giter Site logo

restcord's Introduction

RestCord - PHP Edition

GitHub release Build Status Discord Chat StyleCI

What is this?

This is a PHP library for the Discord API. This library is limited to the basic REST api that Discord provides. If you are doing anything heavy, or fancy, you should probably look at DiscordPHP or Yasmin.

Documentation can be found here.

Wrappers

restcord's People

Contributors

aequasi avatar bkuhl avatar bumbummen99 avatar cryptiklemur avatar dark1z avatar deepdiver1975 avatar donkkill13 avatar dsbilling avatar edwjusti avatar hilbertgilbertson avatar iggyvolz avatar janvernieuwe avatar mikehayesuk avatar nispeon avatar prryplatypus avatar stylecibot avatar svenluijten avatar veteran29 avatar warlof avatar winnak avatar wohali avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

restcord's Issues

channel->getChannelMessages() returns everything no matter what before/after/around is.

Hi!

I'm trying to load all messages that have been posted after a specific message ID,
But no matter what I input, it returns all messages with the limit provided.

Sample message id: 380407098300956691
My Code;
$pull->channel->getChannelMessages(['channel.id' => 000000000000000000,'before'=> 0,'after'=> 380407098300956691,'around'=> 0,'limit'=> 20])

Am I missing something here? (the 000000000000000000 is fake offcourse)

Get Guilds?

Hello, I am trying to make an dashboard and I just want get all guild where my bot are in. Can I make that with restcord? Thanks.

getGuildChannels() misses a model

Two exceptions are thrown when using the getGuildChannels() method:

InvalidArgumentException in Description.php line 163:
No model found named Guild\Channel
(in /var/www/html/vendor/guzzlehttp/guzzle-services/src/Description.php line 163)

And

CommandException in CommandException.php line 57:
There was an error executing the getGuildChannels command: No model found named Guild\Channel
(in /var/www/html/vendor/guzzlehttp/command/src/Exception/CommandException.php line 57)

Bulk Delete functionality missing

Discord's API changed the endpoint from .../bulk_delete to .../bulk-delete and deprecated the old one. The old one appears to be deprecated in restcord's documentation but the new one isn't there. Is the new bulk delete URL supported? It honestly doesn't need to be deprecated, just updated to reference the new URL since the endpoint signature/functionality is the same.

I'd submit a PR to update it, but I think the interfaces are dynamically generated based on the docs and I'm not sure how to go about that.

createMessage return Unauthorized

version package: latest dev-develop
php version: 7.2.3

I can not send a message.

$discord = new RestCord\DiscordClient([
    'token' => 'NTA2NjM5MTIzNTQ5NzgyMDI2.DrlYjw.4xjUu9HHA8FghE5T',
]);

try {
    $discord->channel->createMessage([
        'channel.id' => 5066413984481348,
        'content'    => 'Foo Bar Baz',
    ]);
} catch (GuzzleHttp\Command\Exception\CommandClientException $e) {
    var_dump($e->getResponse()->getBody()->getContents());
}

return

{"code": 40001, "message": "Unauthorized"}

executeWebhook() to return Message

Currently, executeWebhook() returns GuzzleHttp\Command\Result whereas channel->createMessage() returns a RestCord\Model\Channel\Message. Is there a scenario where executeWebhook wouldn't be a single message or would it make sense to have it return a Message?

'Validation errors: [channel.id] must be of type integer

I get an uncaught guzzle exception with this message when trying to run the example message. Using my own bot token and channel id of course. Any idea what I could be doing wrong?

$discord = new DiscordClient(['token' => 'my bot token']); // Token is required

var_dump($discord->channel->createMessage(['channel.id' => 294267349572255744, 'content' => 'Foo Bar Baz']));

Here is the stack trace that is presented.

Fatal error: Uncaught exception 'GuzzleHttp\Command\Exception\CommandException' with message 'Validation errors: [channel.id] must be of type integer' in C:\xampp\htdocs\restcord\vendor\guzzlehttp\guzzle-services\src\Handler\ValidatedDescriptionHandler.php:75 Stack trace: #0 C:\xampp\htdocs\restcord\vendor\guzzlehttp\command\src\ServiceClient.php(85): GuzzleHttp\Command\Guzzle\Handler\ValidatedDescriptionHandler->GuzzleHttp\Command\Guzzle\Handler{closure}(Object(GuzzleHttp\Command\Command)) #1 C:\xampp\htdocs\restcord\vendor\guzzlehttp\command\src\ServiceClient.php(77): GuzzleHttp\Command\ServiceClient->executeAsync(Object(GuzzleHttp\Command\Command)) #2 C:\xampp\htdocs\restcord\vendor\guzzlehttp\command\src\ServiceClient.php(153): GuzzleHttp\Command\ServiceClient->execute(Object(GuzzleHttp\Command\Command)) #3 C:\xampp\htdocs\restcord\main_controller.php(40): GuzzleHttp\Command\ServiceClient->__call('createMessage', Array) #4 C:\xampp\htdocs\restcord\main_controller.php(40): GuzzleHttp\Command\Guzzle\GuzzleClient->creat in C:\xampp\htdocs\restcord\vendor\guzzlehttp\guzzle-services\src\Handler\ValidatedDescriptionHandler.php on line 75

ModifyCurrentUserNick

I'm confused...

ModifyCurrentUserNick throws an error ModifyCurrentUsersNick works

which is the opposite of the docs, and the opposite of the code.

Installation problem

Hello, could you please help me with the installation? It says this when running "composer require restcord/restcord"

Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested package restcord/restcord No version set (parsed as 1.0.0) is satisfiable by restcord/restcord[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability.

Installation failed, reverting ./composer.json to its original content.

service_description.json - "user" category - URL error

Currently, the commands "getCurrentUser", "modifyCurrentUser", "getCurrentUserGuilds", "leaveGuild", "getUserDms", "createDm", "createGroupDm", "getUsersConnections", all contain the url "/users//@me" which should be "/users/@me" instead.

Full Paths:

"$client->user->getCurrentUser()"
"$client->user->modifyCurrentUser()"
"$client->user->getCurrentUserGuilds()"
"$client->user->leaveGuild()"
"$client->user->getUserDms()"
"$client->user->createDm()"
"$client->user->createGroupDm()"
"$client->user->getUsersConnections()"

service_description.json - "invite" responseTypes

Currently, in the commands "getInvite", "deleteInvite", "acceptInvite", the responseTypes have the name "invite object" which should be "invite" since "invite object" throws an error, the model doesn't exist.

The full commands throwing the error are:

"$client->invite->getInvite()"
"$client->invite->deleteInvite()"
"$client->invite->acceptInvite()"

Can we get a new release?

Hey - I know in #2 you're looking for a v1.0.0 release but it seems like there's a lot that has made it into master since the previous release in February. Would it be possible to get an updated release made for the changes? (like a v0.1.5)

convertResponseToResult receives an object instead of array

I was creating a new DM via $client->user->createDm(['recipient_id' => 123]). Unfortunately this fails with the following error:

Argument 1 passed to GuzzleHttp\Command\Result::__construct() must be of the type array, object given, called in vendor/restcord/restcord/src/DiscordClient.php on line 266 in vendor/guzzlehttp/command/src/Result.php on line 14

This can be fixed by casting $data to an array even though I'm not sure, what else it may break.

Issue with modifyGuildRolePositions

Perhaps I am doing something terribly wrong, but I am having no luck with modifyGuildRolePositions. It seems to return an array of guild roles, but does not change the position of the role.

My use example:

$restcord->guild->modifyGuildRolePositions(['guild.id' => 90157169906819070, 'id' => 296755184212639744, 'position' => 4]);

The position of the role does not change (remains at 1) and the returned roles array correctly shows the position number (but has not changed it).

My script has been able to create the role and modify the role fine, but I am having no luck with changing its position.

Fatal error with getChannelMessages()

Hi guys. Having some troubles with getChannelMessages(). In the documentation for this function it says only the 'channel.id' parameter is required, but when I try to run it, it says the other parameters should be an integer?

PHP-code:

`<?php

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

use RestCord\DiscordClient;

$discord = new DiscordClient(['token' => 'token_here']);

$channel_messages = $discord->channel->getChannelMessages(['channel.id' => 386989270566436887, 'limit' => 50]);

var_dump($channel_messages);

?>`

LOG:

Fatal error: Uncaught exception 'GuzzleHttp\Command\Exception\CommandException' with message 'Validation errors: [around] must be of type integer [before] must be of type integer [after] must be of type integer' in /Users/X/Git/tradingsystem/restcord/vendor/guzzlehttp/guzzle-services/src/Handler/ValidatedDescriptionHandler.php:76 Stack trace: #0 /Users/X/Git/tradingsystem/restcord/vendor/guzzlehttp/command/src/ServiceClient.php(85): GuzzleHttp\Command\Guzzle\Handler\ValidatedDescriptionHandler->GuzzleHttp\Command\Guzzle\Handler\{closure}(Object(GuzzleHttp\Command\Command)) #1 /Users/X/Git/tradingsystem/restcord/vendor/guzzlehttp/command/src/ServiceClient.php(77): GuzzleHttp\Command\ServiceClient->executeAsync(Object(GuzzleHttp\Command\Command)) #2 /Users/X/Git/tradingsystem/restcord/vendor/guzzlehttp/command/src/ServiceClient.php(153): GuzzleHttp\Command\ServiceClient->execute(Object(GuzzleHttp\Command\Command)) #3 /Users/X/Git/tradingsystem/restcord/run.php(9): GuzzleHttp\Command\ServiceClient->_ in /Users/X/Git/tradingsystem/restcord/vendor/guzzlehttp/guzzle-services/src/Handler/ValidatedDescriptionHandler.php on line 76

Validation errors: [before] must be of type integer [after] must be of type integer

According to https://discordapp.com/developers/docs/resources/user#get-current-user-guilds these attributes are optional. However, not supplying them throws this exception:

CommandException in ValidatedDescriptionHandler.php line 75:
Validation errors: [before] must be of type integer
[after] must be of type integer

If they're required, this method should really accept multiple parameters rather than accepting an array.

TokenType spaces need stripped before comparison

The tokenType has to be stripped of spaces before comparison as shown below. The OAuth option will set the default 'Bot' if its not stripped.

/**
     * @param string $tokenType
     * @param string $token
     *
     * @return string
     */
    private function getAuthorizationHeader($tokenType, $token)
    {
        switch (str_replace(' ', '', $tokenType)) {
            default:
                $authorization = 'Bot ';
                break;
            case 'User':
                $authorization = '';
                break;
            case 'OAuth':
                $authorization = 'Bearer ';
        }

        return $authorization.$token;
    }

GuildMember join_at type

The join_at of the GuildMember is set to int.
It should be set as string since it is a date.
Setting to int force into giving only the year.

message delete requests not properly rate limited

Looks like RateLimitProvider.php keeps track of different rate limits as follows:

$route = $request->getMethod() .'-'.$request->getUri();

So those requests with the same $route as specified, are considered as the same rate limit. (Hopefully I've got this right.)

Deleting different messages, however, have different routes, but are considered by discord as the same rate limit. Deleting a bunch of messages exceeds the rate limiter because delay is never triggered when it needs to be.

There was an error executing the createChannelInvite command: No model found named Channel\Invite

Here's my code:

$client = new DiscordClient([
'token' => 'my token',
]
);
try{

	$channelId = my channel id;
	$invite = $client->channel->createChannelInvite(['channel.id' => $channelId, 'max_uses'=>1 ]);
}
catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

Here's the error message I get: Caught exception: There was an error executing the createChannelInvite command: No model found named Channel\Invite

apparently it's not getting any model. Anybody encounters the same problem can give me a fix? Thanks

Creation of guild roles ends up creating "new role"

I'm currently working on automating the configuration of a build, but when I call createGuildRole(), It doesn't seem to take the parameters I pass in.

For example:

/Users/thor/src/thor/discord-automation/src/Discord/Helpers.php:26:
array(5) {
  'name' =>
  string(9) "Developer"
  'permissions' =>
  int(2146958463)
  'color' =>
  int(16711680)
  'hoist' =>
  bool(true)
  'mentionable' =>
  bool(false)
}
[2017-02-05 22:29:05] Logger.INFO: https://discordapp.com/api/guilds/270558718985371648/roles POST /api/guilds/270558718985371648/roles HTTP/1.1 Authorization: Bot <TOKEN> User-Agent: DiscordBot (https://github.com/aequasi/php-restcord, 0.1.1 ) Host: discordapp.com   [] []
[2017-02-05 22:29:05] Logger.INFO: HTTP/1.1 200 OK Date: Sun, 05 Feb 2017 22:29:05 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive <some Cloudflare headers>  {"hoist": false, "name": "new role", "mentionable": false, "color": 0, "position": 1, "id": "277928613678940161", "managed": false, "permissions": 104324161} [] []
/Users/thor/src/thor/discord-automation/src/Discord/Helpers.php:30:
class GuzzleHttp\Command\Result#158 (8) {
  public $hoist =>
  bool(false)
  public $name =>
  string(8) "new role"
  public $mentionable =>
  bool(false)
  public $color =>
  int(0)
  public $position =>
  int(1)
  public $id =>
  string(18) "277928613678940161"
  public $managed =>
  bool(false)
  public $permissions =>
  int(104324161)
}

I've wrapped it in a simple class, and call it as the following function:

public function createRole($roleData) {
        $role = [
            'name' => $roleData['name'],
            'permissions' => $roleData['permissions'],
            'color' => $roleData['color'],
            'hoist' => $roleData['hoist'],
            'mentionable' => $roleData['mentionable']
        ];

        echo "creating\n";

        var_dump($role);

        $foo = $this->discord->guild->createGuildRole(array_merge($this->settings, $role));

        var_dump($foo);
}

$this->settings contains ['guild.id' => 270558718985371648].

Moving it out of the wrapper doesn't change the behaviour either, and the parameters, as far as I can tell are correct (https://www.restcord.com/Guild/Create%20Guild%20Role/)

Am I just going crazy here or?

Must be of type int

Hi aequasi,

I'm trying to use this package in Laravel. All is going well. The only thing I needed to do is require it and after that I was able to use it.

There's one thing though that I'm finding a little bit annoying.
I have my bot.key and guild.id in my .env file and I'd like to use it like this:

$info = $discord->guild->getGuild(['guild.id' => env('DISCORD_GUILD')]);

But then it will throw an exception because its an string. I would have to put (int) in front of env() everytime I would use something from the .env file or when I'm using a user's discord.id from the database.
Another form of validation would be highly appreciated!

add member to guild

<?php

  require __DIR__ . '/vendor/autoload.php';

  use Wohali\OAuth2\Client\Provider\Discord;
  use RestCord\DiscordClient;

  session_start();

  $provider = new \Wohali\OAuth2\Client\Provider\Discord([
      'clientId' => 'xxx',
      'clientSecret' => 'xxx',
      'redirectUri' => 'xxx'
  ]);

  if (!isset($_GET['code'])) {

      $authUrl = $provider->getAuthorizationUrl();
      $_SESSION['oauth2state'] = $provider->getState();
      header('Location: ' . $authUrl);

  } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

      unset($_SESSION['oauth2state']);
      exit('Invalid state');

  } else {

    $token = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);

    try {

      $user = $provider->getResourceOwner($token);
      $discord_id = $user->getId();
      $args = [
        'guild.id' => xxx,
        'user.id' => intval($discord_id),
        'access_token' => $token
      ];

      $client = new DiscordClient([
        'token' => 'xxx'
      ]);

      var_dump($client->guild->addGuildMember($args));

    } catch (Exception $e) {
      exit("Oh dear... $e");
    }
  }
?>

this code doesn't work for me, I get 'forbidden' from discord's api

service_description.json - "user" category - DM URL errors

Currently, the commands "getUserDms", "createDm", "createGroupDm", have the urls "/users//@me", which should be "/users/@me/channels" so it works.

Full Commands:

"$client->user->getUserDms()"
"$client->user->createDm()"
"$client->user->createGroupDm()"

Get User Avatar

Hello, I found this afb82dc

But I don't understand aything, anyone can explain how to get user avatar with quick code?

Additional Examples.

A few examples regarding the usage of this wrapper would be useful, such as retrieving users messages and such. I understand this project is the bare bones, but it still needs some more information to even use it.

Validation errors: [limit] must be of type integer [after] must be of type integer

I get an exception when trying to get a list of guild users.
My code:

$guild_id = my_id;
$client = new DiscordClient(['token' => 'my_token']);
var_dump($client->guild->listGuildMembers(['guild.id' => $guild_id]));

The documentation says:

All parameters to this endpoint were optional

Throws an exception:

Fatal error: Uncaught GuzzleHttp\Command\Exception\CommandException: Validation errors: [limit] must be of type integer [after] must be of type integer in E:\OSPanel\domains\discordapp\vendor\guzzlehttp\guzzle-services\src\Handler\ValidatedDescriptionHandler.php:76 Stack trace: #0 E:\OSPanel\domains\discordapp\vendor\guzzlehttp\command\src\ServiceClient.php(85): GuzzleHttp\Command\Guzzle\Handler\ValidatedDescriptionHandler->GuzzleHttp\Command\Guzzle\Handler{closure}(Object(GuzzleHttp\Command\Command)) #1 E:\OSPanel\domains\discordapp\vendor\guzzlehttp\command\src\ServiceClient.php(77): GuzzleHttp\Command\ServiceClient->executeAsync(Object(GuzzleHttp\Command\Command)) #2 E:\OSPanel\domains\discordapp\vendor\guzzlehttp\command\src\ServiceClient.php(153): GuzzleHttp\Command\ServiceClient->execute(Object(GuzzleHttp\Command\Command)) #3 E:\OSPanel\domains\discordapp\index.php(14): GuzzleHttp\Command\ServiceClient->__call('listGuildMember...', Array) #4 {main} thrown in E:\OSPanel\domains\discordapp\vendor\guzzlehttp\guzzle-services\src\Handler\ValidatedDescriptionHandler.php on line 76

getPinnedMessages fails JsonMapper::map() requires first argument to be an object, array given

I've been trying to read the pinned messages of a specific channel. The call works as expected, returning an array as $data. Looking at the $operation the returned payload is:

array:10 [
  "link" => "https://discordapp.com/developers/docs/resources/channel#get-pinned-messages"
  "resource" => "channel"
  "name" => "Get Pinned Messages"
  "method" => "GET"
  "url" => "/channels/{channel.id}/pins"
  "description" => ""
  "responseNote" => "Returns all pinned messages in the channel as an array of message objects."
  "responseTypes" => array:1 [
    0 => array:2 [
      "name" => "message"
      "type" => "channel/message"
    ]
  ]
  "parameters" => array:1 [
    "channel.id" => array:3 [
      "type" => "snowflake"
      "location" => "uri"
      "required" => true
    ]
  ]
  "parametersArray" => false
]

The responseTypes type is channel/message not Array<channel/message>

500 Server error?

What's wrong here? I just get HTTP error 500...
I'm sure it's not my code, because if I swap out createChannelInvite with getChannelInvites it works just fine...

use RestCord\DiscordClient;
  include __DIR__.'/vendor/autoload.php';
  $authToken = 'REMOVED';
  $channel = 'ALSO REMOVED';    // There would be an int here normally, but I removed it for GitHub.

  $discord = new DiscordClient(['token' => $authToken]);
  var_dump($discord->channel->createChannelInvite(['channel.id' => $channel]));

Avatar request feature

Hi aequasi,

as discussed in #20 I would love to see an option that returns the user's avatar url from the Discord cdn.

So we can do something like:

$avatarUrl = $discord->user->getAvatarUrl(['user.id' => (int)$id]);

And maybe add an option for a type of response like img/url.
One would simply return the url, and the other could return a complete html img tag.

Right now I'm using this function in my controller, but it would be a lot easier if it would be included in this package.

	/**
	* Get avatar of the user
	*
	* @param id of the user
	* @param 2nd param is url/img or nothing to default to json
	*
	* @return type url 	returns just the user's avatar url
	* @return type img 	returns html code to show the avatar
	* @return type json returns the url in an json encoded array
	*/
	public function getAvatar(Request $request)
	{
		$id = $request->get('id');
		$type = $request->get('type');

		$user = $this->discord->user->getUser(['user.id' => (int)$id]);
		$url = 'https://cdn.discordapp.com/avatars/'.$id.'/'.$user->avatar.'.webp';

		if ($type == 'url') {
			return $url;
		} elseif ($type == 'img') {
			return '<img src="'.$url.'" alt="'.$user->username.'\'s Avatar">';
		}
		$result = [
			'status' => 'OK',
			'data' => $url
		];
		return response()->json($result);
	}

1.0.0 Release

Need the following things before a 1.0.0 release

  • Rate Limit Handling (429 and Pre-Ratelimit)
  • Logging
  • Support for all REST endpoints
  • Testing of some sort. This will be difficult. Need to mock endpoints.
  • Support different token types (No token, Bot Token, OAuth Token, User Token)
  • Intellisense Helpers (Dummy classes, probably)
  • Response Validation Models
  • Examples
  • Make sure everything works.

If trying to get user 500

var_dump($discord->guild->getGuildMember(['guild.id' => ID, 'user.id' => ID]));

If the user is not on the discord, it will give 500 error, there is nothing catching the error because of the 404.

Unable to use with Laravel 5.6

Hello, I recently found the Laravel wrapper for restcord and decided to give the lib a spin. Well, since the Laravel wrapper requires restcord I figure this is probably the more appropriate place to put this.

When attempting to install restcord on Laravel 5.6, it fails to install since Laravel 5.6 uses v 4.0.4 of symfony/options-resolver and I have no way of rolling this back without breaking my entire install.

So my question is are there plans on updating restcord to function with v 4.0.4 of symfony/options-resolver? The Laravel wrapper is exactly what I've been looking for and would really like to use it but am at a standstill at the moment.

But anyways, here's the error message, just for good measure:

sudo composer require restcord/restcord:dev-master
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

 Problem 1
    - Installation request for restcord/restcord dev-master -> satisfiable by restcord/restcord[dev-master].
    - Conclusion: remove symfony/options-resolver v4.0.4
    - Conclusion: don't install symfony/options-resolver v4.0.4
    - restcord/restcord dev-master requires symfony/options-resolver >=2.6,<=4.0 -> satisfiable by symfony/options-resolver[v2.6.0, v2.6.1, v2.6.10, <Intermediate versions removed for brevity>, v3.4.2, v3.4.3, v3.4.4, v4.0.0].
    - Can only install one of: symfony/options-resolver[v2.6.0, v4.0.4].
    <Intermediate versions removed for brevity>
    - Can only install one of: symfony/options-resolver[v3.1.8, v4.0.4].
    - Can only install one of: symfony/options-resolver[v3.1.9, v4.0.4].
    - Installation request for symfony/options-resolver == 4.0.4.0 -> satisfiable by symfony/options-resolver[v4.0.4].

NULL channels

For some reason whenever I fetch a guild the channels array is always set to NULL. I have checked the permissions and I'm pretty sure there's not a problem there. Any ideas as to why this is happening ?
object(RestCord\Model\Guild\Guild)#183 (31) { ["afk_channel_id"]=> int(421031995179794436) ["afk_timeout"]=> int(300) ["application_id"]=> NULL ["channels"]=> NULL ["default_message_notifications"]=> int(0) ["embed_channel_id"]=> NULL ["embed_enabled"]=> bool(false) ["emojis"]=> array(2) {

$client->channel->editMessage fatal error

This traceback occurs

<b>Fatal error</b>:  Uncaught Error: Class '\RestCord\Model\Channel\ISO8601' not found in /Users/[REDACTED]/PhpstormProjects/[REDACTED]/vendor/netresearch/jsonmapper/src/JsonMapper.php:554
--
  | Stack trace:
  | #0 /Users/[REDACTED]/PhpstormProjects/[REDACTED]/vendor/netresearch/jsonmapper/src/JsonMapper.php(274): JsonMapper-&gt;createInstance('\\RestCord\\Model...', true, '2018-08-26T13:4...')
  | #1 /Users/[REDACTED]/PhpstormProjects/[REDACTED]/vendor/restcord/restcord/src/DiscordClient.php(270): JsonMapper-&gt;map(Object(stdClass), Object(RestCord\Model\Channel\Message))
  | #2 /Users/[REDACTED]/PhpstormProjects/[REDACTED]/vendor/restcord/restcord/src/DiscordClient.php(183): RestCord\DiscordClient-&gt;convertResponseToResult('channel', Array, Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Command\Command))
  | #3 /Users/[REDACTED]/PhpstormProjects/[REDACTED]/vendor/guzzlehttp/command/src/ServiceClient.php(215): RestCord\DiscordClient-&gt;RestCord\{closure}(Object(GuzzleHttp\Psr7\Response), Object(Guzz in <b>/Users/[REDACTED]/PhpstormProjects/[REDACTED]/vendor/netresearch/jsonmapper/src/JsonMapper.php</b> on line <b>554</b><br />

when running

$msg = $bot->channel->editMessage(["channel.id" => BOT_LISTS, "message.id" => $res, "content" => $content]);

where BOT_LISTS is an integer, $res is an integer and $content is a string under 2000 chars.

Any ideas?

modifyChannel - always a bad request

Hello

It seems like I cannot modify the channel because I always get "BAD REQUEST:

[2018-11-12 10:23:03] Logger.INFO: https://discordapp.com/api/v6/channels/864081228706234582 PUT/PATCH /api/v6/channels/864081228706234582 HTTP/1.1 Content-Length: 30 Authorization: Bot <TOKEN> User-Agent: DiscordBot (https://github.com/aequasi/php-restcord, 0.1.1) Host: discordapp.com Content-Type: application/json  {"name":"XXXX","nsfw":false} [] []
[2018-11-12 10:23:03] Logger.INFO: HTTP/1.1 400 Bad Request Server: cloudflare Date: Mon, 12 Nov 2018 09:23:03 GMT Content-Type: text/html Content-Length: 171 Connection: close CF-RAY: -  <html> <head><title>400 Bad Request</title></head> <body bgcolor="white"> <center><h1>400 Bad Request</h1></center> <hr><center>cloudflare</center> </body> </html>  [] []

No matter what kind of parameters I did type in. Even without any.

I can use createMessage to the same channel without an issue though.

RestCord doesn't work on Windows

Tried to run the first example from the docs:

<?php
include __DIR__.'/vendor/autoload.php';
use RestCord\DiscordClient;
$discord = new DiscordClient(['token' => 'bot-token']); // Token is required
var_dump($discord->guild->getGuild(['guild.id' => 81384788765712384])); // i changed the id

Everytime doesn't matter what i got:

Fatal error:  Uncaught GuzzleHttp\Command\Exception\CommandException: Validation errors: [guild.id] must be of type integer in C:\xampp\htdocs\folder\vendor\guzzlehttp\guzzle-services\src\Handler\ValidatedDescriptionHandler.php:76
Stack trace:
#0 C:\xampp\htdocs\folder\vendor\guzzlehttp\command\src\ServiceClient.php(85): GuzzleHttp\Command\Guzzle\Handler\ValidatedDescriptionHandler->GuzzleHttp\Command\Guzzle\Handler\{closure}(Object(GuzzleHttp\Command\Command))
#1 C:\xampp\htdocs\folder\vendor\guzzlehttp\command\src\ServiceClient.php(77): GuzzleHttp\Command\ServiceClient->executeAsync(Object(GuzzleHttp\Command\Command))
#2 C:\xampp\htdocs\folder\vendor\guzzlehttp\command\src\ServiceClient.php(153): GuzzleHttp\Command\ServiceClient->execute(Object(GuzzleHttp\Command\Command))
#3 C:\xampp\htdocs\folder\discordbot.php(10): GuzzleHttp\Command\ServiceClient->__call('getGuild', Array)
#4 {main}
  thrown in C:\xampp\htdocs\folder\vendor\guzzlehttp\guzzle-services\src\Handler\ValidatedDescriptionHandler.php on line 76

Then i tried to run the same script on Ubuntu and it worked first time.
PHP Version on Ubuntu: PHP 7.0.18-0ubuntu0.16.04.1 (cli) ( NTS )
PHP Version local: PHP 7.0.9 (cli) (built: Jul 20 2016 11:08:23) ( ZTS )

Rate limiter exception

When sending many requests quickly, rate limiting throws an exception, even if 'throwOnRatelimit' is set to false.

PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://discordapp.com/api/v6/guilds/XXXX/members?limit=10&after=XXXX resulted in a 429 TOO MANY REQUESTS response:

in /XXXX/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /XXXX/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /XXXX/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /XXXX/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /XXXX/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Prom in /XXXX/vendor/guzzlehttp/command/src/Exception/CommandException.php on line 57

Error

Hi, please help.. (btw. sorry for my english, my english is bad)
Here is my code:

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

use RestCord\DiscordClient;

$discord = new DiscordClient(['token' => 'auth token']); // Token is required

var_dump($discord->channel->createMessage(['channel.id' => 403283706615169025, 'content' => 'Foo Bar Baz']));
var_dump(
    $client->channel->createMessage([
         'channel.id' => $channelId,
         'content'    => "this `supports` __a__ **subset** *of* ~~markdown~~ 😃 ```js
 function foo(bar) {
   console.log(bar);
 }
 
 foo(1);```",
         'embed'      => [
             "title" => "title ~~(did you know you can have markdown here too?)~~",
             "description" => "this supports [named links](https://discordapp.com) on top of the previously shown subset of markdown. ```\nyes, even code blocks```",
             "url" => "https://discordapp.com",
             "color" => 14290439,
             "timestamp" => "2017-02-20T18:05:58.512Z",
             "footer" => [
                 "icon_url" => "https://cdn.discordapp.com/embed/avatars/0.png",
                 "text" => "footer text"
             ],
             "thumbnail" => [
                 "url" => "https://cdn.discordapp.com/embed/avatars/0.png"
             ],
             "image" => [
                 "url" => "https://cdn.discordapp.com/embed/avatars/0.png"
             ],
             "author" => [
                 "name" => "author name",
                 "url" => "https://discordapp.com",
                 "icon_url" => "https://cdn.discordapp.com/embed/avatars/0.png"
             ],
             "fields" => [
                 [
                     "name" => "Foo",
                     "value" => "some of these properties have certain limits..."
                 ],
                 [
                     "name" => "Bar",
                     "value" => "try exceeding some of them!"
                 ],
                 [
                     "name" => " 😃",
                     "value" => "an informative error should show up, and this view will remain as-is until all issues are fixed"
                 ],
                 [
                     "name" => "<:thonkang:219069250692841473>",
                     "value" => "???"
                 ]
             ]
         ]
     ])
 );

500 error:

[2018-02-10 22:07:18] Logger.INFO: https://discordapp.com/api/v6/channels/403283894784491550/messages POST /api/v6/channels/403283894784491550/messages HTTP/1.1 Content-Length: 37 Authorization: Bot <TOKEN> User-Agent: DiscordBot (https://github.com/aequasi/php-restcord, 0.1.1) Host: discordapp.com Content-Type: application/json  {"content":"Foo Bar Baz","tts":false} [] []
[2018-02-10 22:07:18] Logger.INFO: HTTP/1.1 400 BAD REQUEST Date: Sat, 10 Feb 2018 22:07:18 GMT Content-Type: application/json Content-Length: 42 Connection: keep-alive Set-Cookie: __cfduid=d0e1bd83467024ab53c3b24f7284e8c371518300437; expires=Sun, 10-Feb-19 22:07:17 GMT; path=/; domain=.discordapp.com; HttpOnly Strict-Transport-Security: max-age=31536000; includeSubDomains X-RateLimit-Limit: 5 X-RateLimit-Remaining: 3 X-RateLimit-Reset: 1518300439 Via: 1.1 google Alt-Svc: clear Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" Server: cloudflare CF-RAY: 3eb2616918223e20-PRG  {"code": 40001, "message": "Unauthorized"} [] []
PHP Fatal error:  Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://discordapp.com/api/v6/channels/403283894784491550/messages` resulted in a `400 BAD REQUEST` response:

 in /var/werwi/main/conybot/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /var/werwi/main/conybot/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /var/werwi/main/conybot/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /var/werwi/main/conybot/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /var/werwi/main/conybot/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /var/werwi/main/conybot/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(96): GuzzleHttp\P in /var/werwi/main/conybot/vendor/guzzlehttp/command/src/Exception/CommandException.php on line 57

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.