restcord / restcord Goto Github PK
View Code? Open in Web Editor NEWDiscord REST API Client
Home Page: https://www.restcord.com/
License: MIT License
Discord REST API Client
Home Page: https://www.restcord.com/
License: MIT License
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
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!
I'm confused...
ModifyCurrentUserNick
throws an error ModifyCurrentUsersNick
works
which is the opposite of the docs, and the opposite of the code.
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>
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
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);
}
Hey. I can not find how to get information about the user (authorization using this library https://github.com/wohali/oauth2-discord-new). I have an access_token user authorized on the site (he is not a bot). How can I get information from him? I need to know what guilds he has.
If I use RestCord and try to call the getCurrentUser method, I get a 401 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()"
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) {
Need the following things before a 1.0.0 release
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.
"leaveGuild"
currently is missing required parameters and the url is wrong.
Currently the url is "/users//@me"
which should be "/users/@me/guilds/{guild.id}"
.
The parameters should include the guild.id, which it currently has no parameters.
Full Command:
"$client->user->leaveGuild()"
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.
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 )
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.
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;
}
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].
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
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?
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->createInstance('\\RestCord\\Model...', true, '2018-08-26T13:4...')
ย | #1 /Users/[REDACTED]/PhpstormProjects/[REDACTED]/vendor/restcord/restcord/src/DiscordClient.php(270): JsonMapper->map(Object(stdClass), Object(RestCord\Model\Channel\Message))
ย | #2 /Users/[REDACTED]/PhpstormProjects/[REDACTED]/vendor/restcord/restcord/src/DiscordClient.php(183): RestCord\DiscordClient->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->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?
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.
It would be a nice improvement to add the emoji actions on the guild that are described in the discord API (https://discordapp.com/developers/docs/resources/emoji#list-guild-emojis).
I'm looking at the Create Message API doc, and it doesn't details the structure of embed
.
It'd be nice to either have the structure inside the doc, or have a link to the discord API that details such structure.
For ref., the embed
object structure documentation can be found here.
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.
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()"
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)
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.
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.
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]));
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
?
Hello,
We've suddenly been hit with the below error;
There was an error executing the modifyGuildMember command: Client error: `PATCH https://discordapp.com/api/v6/guilds/1111/members/1111` resulted in a `400 BAD REQUEST` response:\n
Never happened before, any ideas?
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 a429 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
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)
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.
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()"
The response type of getReactions should be an array of users according to the documentation.
https://discordapp.com/developers/docs/resources/channel#get-reactions
The response types now are:
"responseTypes": [
{
"name": "user",
"type": "user/user"
}
],
and should be
"responseTypes": [
{
"name": "user",
"type": "ARRAY<user/user>"
}
],
DMChannel
model should implement Channel
, this will create a more object-oriented approach to sending messages.
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
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.
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.
Is there a way to disable the Monolog logger?
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!
Hello, I found this afb82dc
But I don't understand aything, anyone can explain how to get user avatar with quick code?
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"}
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.
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)
<?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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.