Comments (17)
This actually seems to be an issue not specific to textalk/websocket
, but has been discussed in Textalk/websocket-php#50, and seems a solution would be to disable verify_peer
and verify_peer_name
on the context. Possible solution:
// SetupCommand.php
public function getSocket($gateway)
{
$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'verify_peer', false);
stream_context_set_option($context, 'ssl', 'verify_peer_name', false);
return new Client($gateway, ['context' => $context]);
}
from discord.
Okay, so that's why it's returning a 400
. You can get your Discord user ID by turning on developer mode in the Advanced
section of the Appearance
settings window and then right-clicking your username in the user list of a server and selecting Copy ID
. I'll go ahead and add some clarification to the README as well as the method documentation on what exactly should be passed in.
from discord.
Turns out if fsockopen
fails by returning false AND the errno
is 0, it means something went wrong while creating the socket, before connect is even called. From the php docs:
If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket.
I can't say if it has to do with my environment or not? Are there any special dependencies? Does this work on Windows?
from discord.
Just tagged v1.0.7 which should fix this issue.
from discord.
I updated to the latest version but the same error still occurs.
Maybe you should update the textalk/websocket
dependency to ^1.2
. They made changes on the socket creation and fixed a few issues. I'll create a pull request and look for errors for you.
from discord.
Okay so after doing some local tests I found out that executing the command in WSL (Ubuntu) works perfectly fine. This problem seems to be Windows specific.
Anyway I still updated and tested the textalk/websocket
dependency. Related MR: #25
from discord.
Interesting. It may be worth switching to another library to handle the websocket connection, the main reason I chose textalk/websocket
was because of how small it is since it's only needed during the initial setup. I'll start looking into alternative websocket libraries and I'll leave this issue open in the meantime.
from discord.
This seems to have fixed the problem! I suppose we can use the .env
's variables to conditionally add those options to the stream context like this:
// SetupCommand.php
public function getSocket($gateway)
{
$context = stream_context_create();
if (env('APP_ENV') == "local") {
stream_context_set_option($context, 'ssl', 'verify_peer', false);
stream_context_set_option($context, 'ssl', 'verify_peer_name', false);
}
return new Client($gateway, ['context' => $context]);
}
Another variable which could be used is APP_DEBUG
.
I could also think of a command option for discord:setup
to toggle this behaviour. What do you think is best @codyphobe ?
from discord.
Looking at this line:
Could not get a websocket gateway address, defaulting to 'wss://gateway.discord.gg'.
There is also an error connecting to https://discordapp.com/api/gateway
using guzzle. The method used for getSocket()
to disable peer verification could also apply here:
// SetupCommand.php
public function getGateway() {
...
$response = $this->guzzle->get(
'https://discordapp.com/api/gateway',
[
'verify' => env('APP_ENV') != "local"
]
);
...
}
Adding this and the code from my last comment results in the following output:
Is the bot already added to your server? (yes/no) [no]:
> y
Attempting to identify the bot with Discord's websocket gateway...
Connecting to 'wss://gateway.discord.gg'...
Your bot has been identified by Discord and can now send API requests!
If I now change my .env
file to another environment, I get the same errors because SSL verification is active again.
from discord.
In your local environment, after the library has been successfully set up with discord:setup
, does Guzzle complain about SSL verification with normal use of the library without disabling SSL verification?
I would prefer adding an option on the command with a note in the README and printing a feedback message in the terminal if a WebSocket\ConnectionException
is thrown without the option present, but if Guzzle also errors out with normal use of the library then maybe a config flag (e.g. ssl.verify
) that defaults to true
would be best, that way users can choose to disable SSL verification without modifying their environment.
Either way I think it's necessary to add a footnote in the README about making sure that PHP is configured properly on Windows for users that experience this problem [1, 2]
from discord.
No, it does not work:
NotificationChannels\Discord\Exceptions\CouldNotSendNotification : Communication with Discord failed: 0: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
I'd say add an option to the command to disable it once but if users want to use it that way it should still fail. Maybe check if ssl is set up and warn the user to avoid cryptic error messages.
from discord.
Just tried it again with the certificate in place and got error 400:
NotificationChannels\Discord\Exceptions\CouldNotSendNotification : Discord responded with an HTTP error: 400
It occured while getting the private channel to a Discord Username. Probably not related to the ssl error but do you know what could have caused this?
from discord.
Out of curiosity, why is baseUrl not requesting v6
?
Line 18 in 2d3501b
Line 82 in 2d3501b
See Connecting to the Gateway from the Discord Docs.
from discord.
The API version isn't specified so that it will default to the latest version.
As for the 400
error, I'm unsure as there are a number of things that can go wrong. A DM could fail because it's too long, the user has blocked the bot, the user has public DMs disabled, the bot account has them disabled, or the message is malformed. It's worth noting that while trying to replicate the 400
error, I could only get a 403
when the user had public DMs disabled.
from discord.
It didn't even get to sending a DM. The error occured while getting the private channel for my username.
At least the ssl error is fixed now. For me, this issue can be closed now. As for the 400 error, I'll look into it tomorrow and open a new issue for it's own discussions if I find anything related to it.
from discord.
The error occured while getting the private channel for my username.
Did you pass a username into getPrivateChannel
? If so, that method and API route expects the snowflake ID for a user. That's my bad for not being specific in that method's documentation; all it says is "user", I wouldn't expect you to know that it needed an ID without having to look at the source.
I don't see any non-OAuth Discord API for getting a user's id from the username and tag, otherwise I would just add that to the method. The best bet seems to be just asking users to copy & paste their ID manually or allow them to login with Discord and store their ID from the OAuth flow.
from discord.
I used my username in the form of "Mizzle#8643".
from discord.
Related Issues (20)
- Discord channel can not be queued. HOT 3
- Laravel 7 Support HOT 1
- HTTP error: 403: Cannot send messages to this user HOT 1
- Discord responded with an HTTP error: 403: Missing Access
- Laravel 8 Support HOT 1
- Discord error response data discarded HOT 1
- PHP 8.0 support HOT 1
- Laravel doesn't identify the bot HOT 1
- DiscordPHP will not run on a webserver. Please use PHP CLI to run a DiscordPHP bot.
- README needs improving.
- Config not recognized ?!?!
- Laravel 9 Compatibility HOT 2
- Dynamic discord channel for each Notification class? HOT 4
- Driver [Discord] not supported HOT 1
- Discord webhook support per user
- Send embed message with image
- Retry sending a notification if you're being rate limited by Discord HOT 1
- Blank Fields Not working
- Discord Bot Always Offline HOT 1
- Getting `400 Bad Request` response: {\"embed\": [\"Expected an object/dictionary.\"]} HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from discord.