gpt4 book ai didi

php - Discord PHP 从 channel ID 创建邀请链接

转载 作者:行者123 更新时间:2023-12-04 14:47:12 24 4
gpt4 key购买 nike

我正在用 php 开发一个 discord 机器人。我想通过 DiscordPHP 创建邀请链接包。

这是我写的

include __DIR__.'/vendor/autoload.php';
use Discord\Discord;
$discord = new Discord([
'token' => 'MY_TOKKEN',
]);
$discord->on('ready', function ($discord) {
echo "Bot is ready!", PHP_EOL;
$discord->on('message', function ($message, $discord) {
$channel = $message->channel;
$channel->createInvite([
'max_age' => 60,
'max_uses' => 5,
])->done(function (Invite $invite) {
echo $invite->code;
});
});
});
$discord->run();

echo $invite->code; 我没有收到任何我用来分享的响应字符串。

最佳答案

我不知道 discord lib ,但你可以通过 make var_dump($invite) 调试并检查结果,如果你得到任何东西我的更新运行这个

include __DIR__.'/vendor/autoload.php';
use Discord\Discord;
$discord = new Discord([
"token" => "your token",
]);
$discord->on('ready', function ($discord) {
echo "Bot is ready!", PHP_EOL;
$discord->on('message', function ($message, $discord) {
$channel = $message->channel;
$channel->createInvite([
'max_age' => 60,
'max_uses' => 5,
])->done(function (Invite $invite) {
echo $invite->code;
});
});
}); $discord->run();

并检查机器人允许邀请的 discord 权限

关于php - Discord PHP 从 channel ID 创建邀请链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69817567/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com