Fix redirection to DM channels

This commit is contained in:
kageru 2019-07-11 23:30:39 +02:00
parent de0145a6c6
commit e3ab2d512f
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -70,8 +70,12 @@ object Util {
?: throw IllegalArgumentException("Channel ID $idOrName not found.")
else -> if (idOrName.startsWith('@')) {
api.getCachedUserByDiscriminatedName(idOrName.removePrefix("@")).ifNotEmpty { user ->
user.privateChannel.ifNotEmpty { it }
?: throw IllegalArgumentException("Could not open private channel with user $idOrName for redirection.")
val channelFuture = user.openPrivateChannel()
val channel = channelFuture.join()
if (channelFuture.isCompletedExceptionally) {
throw IllegalArgumentException("Could not open private channel with user $idOrName for redirection.")
}
channel
}
?: throw IllegalArgumentException("Can’t find user $idOrName for redirection.")
} else {