Closed weichenlin closed 3 years ago
try ...->sendMessage("your message here")->then(null, function($response) { dump($response); });
also, based on your trace, it means you do not have GUILD_MEMBERS enabled in both the dev console and in the intents, see the changelog
this's my config
$discord = new Discord([
'token' => $myToken,
'intents' => Intents::getDefaultIntents() | Intents::GUILD_MEMBERS,
'loadAllMembers' => true,
]);
in discord developer portal, bot page:
I changed code to
$guild->channels->fetch($myChannelId, true)->done(function (Channel $ch) {
echo "got channel\n";
$ch->sendMessage('from fetch channelId')->then(null, function($response) { var_dump($response); });
echo "done\n";
});
and got:
[2021-04-21T17:02:58.884986+00:00] DiscordPHP.DEBUG: REQ GET channels/767679967327682581 successful [] []
got channel
[2021-04-21T17:03:38.658914+00:00] DiscordPHP.DEBUG: sending heartbeat {"seq":4} []
the var_dump and the msg "done" are not appear I didn't see the msg on discord as well
Why was the fix removed? Faced exactly the same problem, fixed it as in the commit:
// src/Discord/Parts/Channel/Channel.php
// public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): ExtendedPromiseInterface
if (! $this->is_private && $member = $this->guild->members->offsetGet($this->discord->id)) {
$botperms = $member->getBotPermissions();
// ...
Why was the fix removed? Faced exactly the same problem, fixed it as in the commit:
// src/Discord/Parts/Channel/Channel.php // public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): ExtendedPromiseInterface if (! $this->is_private && $member = $this->guild->members->offsetGet($this->discord->id)) { $botperms = $member->getBotPermissions(); // ...
Sorry, the fix was simplified but overlooked, it was never removed. It is another new bug. It will be fixed soon (dev-master# c50d947 ), thanks for reporting!
But in future, please do not follow the practice of freshening Guild & Channel (avoid the code in this issue) when not necessary.
Environment
Describe the bug when I get channel by
$guild->channels->fetch()
the$channel->sendMessage()
silent failsTo Reproduce Steps to reproduce the behavior:
Expected behavior should see both message on discord channel
Additional context use xdebug to trace code, an exception are thrown on Channel.php line 708:
$botperms = $this->guild->members->offsetGet($this->discord->id)->getPermissions($this);
the exception is : Call to a member function getPermissions() on null